util-vserver:InitStyles

From Linux-VServer

Revision as of 02:30, 2 February 2007 by KornAndras (Talk | contribs)

Jump to: navigation, search

Guests can be started using one of the following init styles:

  • plain
    • Launches a unique init process for the guest that appears to run as PID 1.
    • Guest's init process executes the rc scripts.
    • Therefore, you cannot watch the startup process.
    • However, any shutdown or restart command should work
  • sysv (default)
    • Executes the runlevel scripts directly.
    • You can watch the startup process.
    • Slightly lighter weight since no additional init process is needed.
    • The vserver sees a fake init with PID 1 that has the same properties as the real init on the host.
    • You must use "reboot -f" or "halt -f" to restart or shut down from within the guest.
  • gentoo
    • Like sysv but works on Gentoo-based guests.
    • Was deprecated but has been reinstated around util-vserver 0.30.212.
  • minit

Configuration

The init style should go in a file containing a single word: sysv, plain, etc.

 /etc/vservers/<NAME>/apps/init/style

If the file doesn't exist, sysv will be used. If the word isn't recognized, the guest will not be started and an error will be printed.

Using runit

runit is an init replacement that provides service monitoring. There currently are at least three ways to use it with vserver:

  • Set initstyle to plain; this allows you to launch your own runit inside the vserver.
  • Set initstyle to sysv, but cmd.start to "/etc/runit/2" and cmd.stop to "/etc/runit/3".
  • Use a persistent context for the guest, and just run the services inside it, not runit itself. This is discussed in Running runit-supervised services inside a vserver.

I haven't tried the first way; the second way has the advantage that you can run a vserver under runit running on the host.

For this to work, you must customize /etc/runit/2 in the vserver as follows:

#!/bin/sh

trap ":" HUP INT QUIT ILL TRAP ABRT BUS FPE USR1 SEGV USR2 PIPE ALRM TERM CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS

PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin

runsvchdir default >/dev/null

env - PATH=$PATH \
runsvdir -P /var/service 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'

exec /etc/runit/3

Now, you can set up a runit service on the host with a run script like this one:

#!/bin/sh
exec 2>&1
exec vserver name-of-vserver start

This way:

  • vserver start doesn't exit until runsvdir terminates.
  • If runsvdir terminates, all services running inside the vserver are stopped.
  • vserver stop works as expected.
    • Update: with util-vserver 0.30.212 on amd64, it doesn't. The signal never reaches runsvdir.
  • You can control the vserver using sv like any other service, provided all processes running inside it are managed by runit.
    • If there are processes left inside after all the services exited, runit running on the host won't be able to restart the vserver until those stray processes are killed somehow.
    • You may want to add something to this effect to the finish script of the vserver service, but it may not be a good idea. Be sure you know what you are doing, as always.

Still, this may not be the best way to integrate runit with vserver. I now believe the best way is running runit-supervised services inside a vserver without imitating anything like init in the guest.

--Guy- 02:30, 2 February 2007 (CET)

Personal tools