[libvirt-users] How can a user process be automatically started after the container is started?

Dear All, I want to start my application automatically after I start the container with a virsh command " virsh -c lxc:/// start mycontainer" How can I achieve this? Thank you in advance. Cheng

On Thu, Oct 23, 2014 at 05:09:50AM +0000, WANG Cheng D wrote:
Dear All,
I want to start my application automatically after I start the container with a virsh command " virsh -c lxc:/// start mycontainer" How can I achieve this?
Whatever you specify as the <init>....</init> binary in the container XML file is started when the container is created. If you only want 1 application to run, then this is straightforward. If you want to run multiple applications either point the "init" binary to a shell script to run the many things, or better yet use a real init system like systemd to spawn off the things you need. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Dear Daniel, You said "use a real init system like systemd to spawn off the things", do you mean a full OS distro container? I installed the container using "yum --installroot=/root/fedora19lxc --releasever=19 install -y openssh, bridge-utils" which is described at https://www.redhat.com/archives/libvirt-users/2013-August/msg00007.html. I don't know how to make systemd work in my current container. And I don't know how to install a full OS distro container either. Could you give me more guidance? With my warmest regards, Cheng -----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: 2014年10月23日 16:11 To: WANG Cheng D Cc: libvirt-users@redhat.com Subject: Re: [libvirt-users] How can a user process be automatically started after the container is started? On Thu, Oct 23, 2014 at 05:09:50AM +0000, WANG Cheng D wrote:
Dear All,
I want to start my application automatically after I start the container with a virsh command " virsh -c lxc:/// start mycontainer" How can I achieve this?
Whatever you specify as the <init>....</init> binary in the container XML file is started when the container is created. If you only want 1 application to run, then this is straightforward. If you want to run multiple applications either point the "init" binary to a shell script to run the many things, or better yet use a real init system like systemd to spawn off the things you need. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Fri, Oct 24, 2014 at 08:03:59AM +0000, WANG Cheng D wrote:
Dear Daniel,
You said "use a real init system like systemd to spawn off the things", do you mean a full OS distro container?
I installed the container using "yum --installroot=/root/fedora19lxc --releasever=19 install -y openssh, bridge-utils" which is described at https://www.redhat.com/archives/libvirt-users/2013-August/msg00007.html.
I don't know how to make systemd work in my current container. And I don't know how to install a full OS distro container either. Could you give me more guidance?
If you install a modern Fedora distro in a chroot and use that as the filesystem for the container, then you have a container that uses systemd for startup. There is nothing special you should ned todo with system - it ought to "just work" as systemd is designed to easily cope with running inside a container. For reference see also this: https://www.berrange.com/posts/2013/08/12/running-a-full-fedora-os-inside-a-... Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
WANG Cheng D