summaryrefslogtreecommitdiffstats
path: root/main/lxc/lxc.initd
diff options
context:
space:
mode:
Diffstat (limited to 'main/lxc/lxc.initd')
-rw-r--r--main/lxc/lxc.initd172
1 files changed, 77 insertions, 95 deletions
diff --git a/main/lxc/lxc.initd b/main/lxc/lxc.initd
index 86bae5f75..a77ba0e86 100644
--- a/main/lxc/lxc.initd
+++ b/main/lxc/lxc.initd
@@ -1,114 +1,96 @@
#!/sbin/runscript
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/files/lxc.initd,v 1.3 2011/02/26 18:02:51 flameeyes Exp $
+# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/files/lxc.initd.2,v 1.5 2012/07/21 05:07:15 flameeyes Exp $
CONTAINER=${SVCNAME#*.}
-CONFIGFILE=${CONFIGFILE:-/etc/lxc/${CONTAINER}.conf}
+command="/usr/bin/lxc-start"
+pidfile="/var/run/lxc/$CONTAINER.pid"
+extra_started_commands="reboot"
-lxc_get_var() {
- awk 'BEGIN { FS="[ \t]*=[ \t]*" } $1 == "'$1'" { print $2; exit }' ${CONFIGFILE}
+depend() {
+ need localmount
}
-cgroup_get_mount() {
- mount | awk '$5 == "cgroup" { print $3; exit }'
+lxc_get_configfile() {
+ if [ -f "/etc/lxc/${CONTAINER}.conf" ]; then
+ echo "/etc/lxc/${CONTAINER}.conf"
+ elif [ -f "/etc/lxc/${CONTAINER}/config" ]; then
+ echo "/etc/lxc/${CONTAINER}/config"
+ else
+ eerror "Unable to find a suitable configuration file."
+ eerror "If you set up the container in a non-standard"
+ eerror "location, please set the CONFIGFILE variable."
+ return 1
+ fi
}
-checkconfig() {
- if [ ${CONTAINER} = ${SVCNAME} ]; then
- eerror "You have to create an init script for each container:"
- eerror " ln -s lxc /etc/init.d/lxc.container"
- return 1
- fi
-
- utsname=$(lxc_get_var lxc.utsname)
- if [ ${CONTAINER} != ${utsname} ]; then
- eerror "You should use the same name for the service and the"
- eerror "container. Right now the container is called ${utsname}"
- return 1
- fi
+lxc_get_var() {
+ awk 'BEGIN { FS="[ \t]*=[ \t]*" } $1 == "'$1'" { print $2; exit }' ${CONFIGFILE}
}
-depend() {
- # be quiet, since we have to run depend() also for the
- # non-muxed init script, unfortunately.
- checkconfig 2>/dev/null || return 0
-
- config ${CONFIGFILE}
- need localmount
-
- # find out which network interface the container is linked to,
- # and then require that to be enabled, so that the
- # dependencies are correct.
- netif=$(lxc_get_var lxc.network.link)
- [ -n "${netif}" ] && need net.${netif}
+checkconfig() {
+ if [ ${CONTAINER} = ${SVCNAME} ]; then
+ eerror "You have to create an init script for each container:"
+ eerror " ln -s lxc /etc/init.d/lxc.container"
+ return 1
+ fi
+ CONFIGFILE=${CONFIGFILE:-$(lxc_get_configfile)}
+
+ # no need to output anything, the function takes care of that.
+ [ -z "${CONFIGFILE}" ] && return 1
+
+ utsname=$(lxc_get_var lxc.utsname)
+ if [ ${CONTAINER} != ${utsname} ]; then
+ eerror "You should use the same name for the service and the"
+ eerror "container. Right now the container is called ${utsname}"
+ return 1
+ fi
}
start() {
- checkconfig || return 1
-
- # make sure that cgroup is mounted if it isn't already, this
- # ensures that we can actually proceed!
- cgroupmount=$(cgroup_get_mount)
- if [ -z ${cgroupmount} ]; then
- mkdir -p /cgroup
-
- if ! mount -t cgroup cgroup /cgroup; then
- eerror "Unable to mount cgroup pseudo-filesystem on /cgroup"
- return 1
- fi
-
- cgroupmount=/cgroup
- fi
-
- rm /var/log/lxc/${CONTAINER}.log
-
- rootpath=$(lxc_get_var lxc.rootfs)
-
- # Check the format of our init and the chroot's init, to see if we
- # have to use linux32 or linux64…
- case $(scanelf -BF '%M#f' /sbin/init ${rootpath}/sbin/init | tr '\n' ':') in
- ELFCLASS64:ELFCLASS64:) setarch=;;
- ELFCLASS32:ELFCLASS32:) setarch=;;
- ELFCLASS32:ELFCLASS64:) setarch=linux64;;
- ELFCLASS64:ELFCLASS32:) setarch=linux32;;
- esac
-
- ebegin "Starting ${CONTAINER}"
- ${setarch} lxc-start -l WARN -n ${CONTAINER} -f ${CONFIGFILE} -d -o /var/log/lxc/${CONTAINER}.log
- sleep 0.5
-
- # lxc-start -d will _always_ report a correct startup, even if it
- # failed, so rather than trust that, check that the cgroup exists.
- [ -d ${cgroupmount}/${CONTAINER} ]
- eend $?
+ checkconfig || return 1
+ rm -f /var/log/lxc/${CONTAINER}.log
+
+ rootpath=$(lxc_get_var lxc.rootfs)
+ checkpath -d ${pidfile%/*}
+ ebegin "Starting ${CONTAINER}"
+ start-stop-daemon --start $command \
+ --pidfile $pidfile \
+ --wait 500 \
+ -- \
+ --daemon \
+ --pidfile $pidfile \
+ --name ${CONTAINER} \
+ --rcfile ${CONFIGFILE} \
+ --logpriority WARN \
+ --logfile /var/log/lxc/${CONTAINER}.log
+ eend $?
}
stop() {
- checkconfig || return 1
-
- cgroupmount=$(cgroup_get_mount)
-
- if ! [ -d ${cgroupmount}/${CONTAINER} ]; then
- ewarn "${CONTAINER} doesn't seem to be started."
- return 0
- fi
-
- init_pid=$(head -n1 ${cgroupmount}/${CONTAINER}/tasks)
-
- ebegin "Shutting down system in ${CONTAINER}"
- kill -INT ${init_pid}
- eend $?
-
- sleep 15
-
- missingprocs=$(pgrep -P ${init_pid})
-
- if [ -n "${missingprocs}" ]; then
- ewarn "Something failed to properly shut down in ${CONTAINER}"
- fi
+ checkconfig || return 1
+
+ if ! [ -d /sys/fs/cgroup/cpuset/lxc/${CONTAINER} ]; then
+ ewarn "${CONTAINER} doesn't seem to be started."
+ return 0
+ fi
+
+ ebegin "Shutting down system in ${CONTAINER}"
+ start-stop-daemon --stop --pidfile ${pidfile} \
+ --retry ${POWEROFF_SIGNAL:-SIGUSR2}/${TIMEOUT:-30} \
+ --progress
+ eend $?
+
+ ebegin "Stopping ${CONTAINER}"
+ lxc-stop -n ${CONTAINER}
+ eend $?
+}
- ebegin "Stopping ${CONTAINER}"
- lxc-stop -n ${CONTAINER}
- eend $?
+reboot() {
+ checkconfig || return 1
+ ebegin "Sending reboot signal to $CONTAINER"
+ start-stop-daemon --signal ${RESTART_SIG:-SIGTERM} \
+ --pidfile ${pidfile}
+ eend $?
}