Permalink
Please sign in to comment.
Browse files
FL-744: correct lxc init script to support Funtoo's corenetwork
- Loading branch information...
Showing
with
576 additions
and 0 deletions.
@@ -0,0 +1,4 @@ | ||
+DIST lxc-0.8.0-backports-1.tar.xz 2424 SHA256 5b68b96b9fbc2d0f5b2ad2e7fb996a3d837114237a306de39d9939f31756a522 SHA512 9898d78836cc546e80015a18070e3976118d2efb006584ecfb2887a4474598766e023eb6c120c16dae2e94dddc33c8a4e928fd44bc6fb2260a1913c06f5d374e WHIRLPOOL ef11f25ec8891f431be7aed32b38c0cc51e1096a37ea71c38aed4448ab0305784b510e2b55bdc73e5ef2128344a6c88adb3add798323f77e276b5185e53f5ef9 | ||
+DIST lxc-0.8.0-rc2-backports-2.tar.xz 4616 SHA256 c371817b5be47ed70dea410a32dc434a060073992d5299d2c88853de79aa2111 SHA512 ca646ae325a4cf94632c443397834a8a7dc004874b528d2d685b698b3eda1e72e09ecfd68899b9c0cd17d5d7bf1a62230dd6d17d26f73d2d4ecbf1932c31b996 WHIRLPOOL 76deca3e2b7fe306c0e2f538759fb33656f08c52d1b59570edc6f3d2444d387a0f7944f759baf41402e747eb055ab403a82a40b95ba0c7d42d0644a5f990e851 | ||
+DIST lxc-0.8.0-rc2.tar.gz 302999 SHA256 1f0ee0464507d26e494784e841b68c765ecd3abc5976012e226f69d1aa361bef SHA512 e6608f980489f67d412c9a50f8c3f65c1afbba520dfdfe2b695c597c2706544291f31c8cfca2d86cfbab09029f8a5706fae5ab72f1c45dccca5f7e2ae8851181 WHIRLPOOL b41fe7e14315b9e6702070535edfee68379c01fba23d143c5f11afa20f6d392c8bc32953da46ec3f74d7a2affe9f828d918f23a8a16c430e3b8ffcc9b2c10057 | ||
+DIST lxc-0.8.0.tar.gz 309973 SHA256 eac833730b94e423d4bef6834bc4a716437d2abd6ab8b24334c506aaaa08692c SHA512 47333e2010d0f4488b8876ba933f2d26304874bec0371a7ab3b6e5bd1a50a7d2312ff8507e273f1ee2341a7f2e3b79cd71e5e19ac31006a4e429ee96b01733f6 WHIRLPOOL 693b7d354dec7c6102d5ce3a42a9b618e213fd9ee8c592068ebadb7f25094606abce6c3da77b483fab0938410215010f71d487f336856c87327d6a98f20b65dd |
@@ -0,0 +1,132 @@ | ||
+#!/sbin/runscript | ||
+# 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.2,v 1.6 2012/11/14 02:15:10 flameeyes Exp $ | ||
+ | ||
+CONTAINER=${SVCNAME#*.} | ||
+ | ||
+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 | ||
+} | ||
+ | ||
+[ $CONTAINER != $SVCNAME ] && CONFIGFILE=${CONFIGFILE:-$(lxc_get_configfile)} | ||
+ | ||
+lxc_get_var() { | ||
+ awk 'BEGIN { FS="[ \t]*=[ \t]*" } $1 == "'$1'" { print $2; exit }' ${CONFIGFILE} | ||
+} | ||
+ | ||
+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 | ||
+ | ||
+ # 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 | ||
+} | ||
+ | ||
+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) | ||
+ | ||
+ # when the network type is set to phys, we can make use of a | ||
+ # network service (for instance to set it up before we disable | ||
+ # the net_admin capability), but we might also not set it up | ||
+ # at all on the host and leave the net_admin capable service | ||
+ # to take care of it. | ||
+ nettype=$(lxc_get_var lxc.network.type) | ||
+ | ||
+ if [ -n "${netif}" ]; then | ||
+ case "${nettype}" in | ||
+ phys) use net.${netif} ;; | ||
+ *) need net.${netif} ;; | ||
+ esac | ||
+ fi | ||
+} | ||
+ | ||
+start() { | ||
+ checkconfig || return 1 | ||
+ 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; always use setarch | ||
+ # when required, as that makes it easier to deal with | ||
+ # x32-based containers. | ||
+ case $(scanelf -BF '%a#f' ${rootpath}/sbin/init) in | ||
+ EM_X86_64) setarch=linux64;; | ||
+ EM_386) setarch=linux32;; | ||
+ esac | ||
+ | ||
+ ebegin "Starting ${CONTAINER}" | ||
+ env -i ${setarch} $(type -p 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 /sys/fs/cgroup/cpuset/lxc/${CONTAINER} ] | ||
+ eend $? | ||
+} | ||
+ | ||
+stop() { | ||
+ checkconfig || return 1 | ||
+ | ||
+ | ||
+ if ! [ -d /sys/fs/cgroup/cpuset/lxc/${CONTAINER} ]; then | ||
+ ewarn "${CONTAINER} doesn't seem to be started." | ||
+ return 0 | ||
+ fi | ||
+ | ||
+ init_pid=$(lxc-info -n ${CONTAINER} --pid | awk '{ print $2 }') | ||
+ | ||
+ if [ "${init_pid}" = "-1" ]; then | ||
+ ewarn "${CONTAINER} doesn't seem to be running." | ||
+ return 0 | ||
+ fi | ||
+ | ||
+ ebegin "Shutting down system in ${CONTAINER}" | ||
+ kill -PWR ${init_pid} | ||
+ eend $? | ||
+ | ||
+ TIMEOUT=${TIMEOUT:-30} | ||
+ i=0 | ||
+ while [ -n "$(pgrep -P ${init_pid})" -a $i -lt ${TIMEOUT} ]; do | ||
+ sleep 1 | ||
+ i=$(expr $i + 1) | ||
+ done | ||
+ | ||
+ if [ -n "${missingprocs}" ]; then | ||
+ ewarn "Something failed to properly shut down in ${CONTAINER}" | ||
+ fi | ||
+ | ||
+ ebegin "Stopping ${CONTAINER}" | ||
+ lxc-stop -n ${CONTAINER} | ||
+ eend $? | ||
+} |
@@ -0,0 +1,130 @@ | ||
+#!/sbin/runscript | ||
+# Distributed under the terms of the GNU General Public License v2 | ||
+ | ||
+CONTAINER=${SVCNAME#*.} | ||
+ | ||
+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 | ||
+} | ||
+ | ||
+[ $CONTAINER != $SVCNAME ] && CONFIGFILE=${CONFIGFILE:-$(lxc_get_configfile)} | ||
+ | ||
+lxc_get_var() { | ||
+ awk 'BEGIN { FS="[ \t]*=[ \t]*" } $1 == "'$1'" { print $2; exit }' ${CONFIGFILE} | ||
+} | ||
+ | ||
+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 | ||
+ | ||
+ # 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 | ||
+} | ||
+ | ||
+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) | ||
+ | ||
+ # when the network type is set to phys, we can make use of a | ||
+ # network service (for instance to set it up before we disable | ||
+ # the net_admin capability), but we might also not set it up | ||
+ # at all on the host and leave the net_admin capable service | ||
+ # to take care of it. | ||
+ nettype=$(lxc_get_var lxc.network.type) | ||
+ | ||
+ if [ -n "${netif}" ]; then | ||
+ case "${nettype}" in | ||
+ phys) use netif.${netif} ;; | ||
+ *) need netif.${netif} ;; | ||
+ esac | ||
+ fi | ||
+} | ||
+ | ||
+start() { | ||
+ checkconfig || return 1 | ||
+ 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; always use setarch | ||
+ # when required, as that makes it easier to deal with | ||
+ # x32-based containers. | ||
+ case $(scanelf -BF '%a#f' ${rootpath}/sbin/init) in | ||
+ EM_X86_64) setarch=linux64;; | ||
+ EM_386) setarch=linux32;; | ||
+ esac | ||
+ | ||
+ ebegin "Starting ${CONTAINER}" | ||
+ env -i ${setarch} $(type -p 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 /sys/fs/cgroup/cpuset/lxc/${CONTAINER} ] | ||
+ eend $? | ||
+} | ||
+ | ||
+stop() { | ||
+ checkconfig || return 1 | ||
+ | ||
+ | ||
+ if ! [ -d /sys/fs/cgroup/cpuset/lxc/${CONTAINER} ]; then | ||
+ ewarn "${CONTAINER} doesn't seem to be started." | ||
+ return 0 | ||
+ fi | ||
+ | ||
+ init_pid=$(lxc-info -n ${CONTAINER} --pid | awk '{ print $2 }') | ||
+ | ||
+ if [ "${init_pid}" = "-1" ]; then | ||
+ ewarn "${CONTAINER} doesn't seem to be running." | ||
+ return 0 | ||
+ fi | ||
+ | ||
+ ebegin "Shutting down system in ${CONTAINER}" | ||
+ kill -PWR ${init_pid} | ||
+ eend $? | ||
+ | ||
+ TIMEOUT=${TIMEOUT:-30} | ||
+ i=0 | ||
+ while [ -n "$(pgrep -P ${init_pid})" -a $i -lt ${TIMEOUT} ]; do | ||
+ sleep 1 | ||
+ i=$(expr $i + 1) | ||
+ done | ||
+ | ||
+ if [ -n "${missingprocs}" ]; then | ||
+ ewarn "Something failed to properly shut down in ${CONTAINER}" | ||
+ fi | ||
+ | ||
+ ebegin "Stopping ${CONTAINER}" | ||
+ lxc-stop -n ${CONTAINER} | ||
+ eend $? | ||
+} |

Oops, something went wrong.
0 comments on commit
28d14b0