[packages/lxc] Added PLD init.
matkor
matkor at pld-linux.org
Thu Jul 31 14:48:51 CEST 2014
commit 4a25e08f546794a98e2c2a003c325b7ffe96954a
Author: Mateusz Korniak <matkor at pld-linux.org>
Date: Thu Jul 31 14:25:09 2014 +0200
Added PLD init.
lxc.init | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 142 insertions(+)
---
diff --git a/lxc.init b/lxc.init
new file mode 100755
index 0000000..eb95ace
--- /dev/null
+++ b/lxc.init
@@ -0,0 +1,142 @@
+#!/bin/sh
+#
+# lxc Start/Stop LXC autoboot containers
+#
+# chkconfig: 345 99 01
+# description: Starts/Stops all LXC containers configured for autostart.
+#
+### BEGIN INIT INFO
+# Provides: lxc
+# Default-Start: 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Bring up/down LXC autostart containers
+# Description: Bring up/down LXC autostart containers
+### END INIT INFO
+
+# set -x
+
+sysconfdir="/etc"
+bindir="/usr/bin"
+localstatedir="/var"
+
+# These can be overridden in /etc/sysconfig/lxc
+
+# BOOTGROUPS - What groups should start on bootup?
+# Comma separated list of groups.
+# Leading comma, trailing comma or embedded double
+# comma indicates when the NULL group should be run.
+# Example (default): boot the onboot group first then the NULL group
+BOOTGROUPS="onboot,"
+
+# SHUTDOWNDELAY - Wait time for a container to shut down.
+# ner shutdown can result in lengthy system
+# shutdown times. Even 5 seconds per container can be
+# too long.
+SHUTDOWNDELAY=5
+
+# OPTIONS can be used for anything else.
+# If you want to boot everything then
+# options can be "-a" or "-a -A".
+OPTIONS=
+
+# STOPOPTS are stop options. The can be used for anything else to stop.
+# If you want to kill containers fast, use -k
+STOPOPTS="-a -s"
+
+# Source function library.
+test ! -r "$sysconfdir"/rc.d/init.d/functions ||
+ . "$sysconfdir"/rc.d/init.d/functions
+
+# Source any configurable options
+test ! -r "$sysconfdir"/sysconfig/lxc ||
+ . "$sysconfdir"/sysconfig/lxc
+
+# Check for needed utility program
+[ -x "$bindir"/lxc-autostart ] || exit 1
+
+# If libvirtd is providing the bridge, it might not be
+# immediately available, so wait a bit for it before starting
+# up the containers or else any that use the bridge will fail
+# to start
+wait_for_bridge()
+{
+ [ -f "$sysconfdir"/lxc/default.conf ] || { return 0; }
+
+ which ifconfig >/dev/null 2>&1
+ if [ $? = 0 ]; then
+ cmd="ifconfig -a"
+ else
+ which ip >/dev/null 2>&1
+ if [ $? = 0 ]; then
+ cmd="ip link list"
+ fi
+ fi
+ [ -n cmd ] || { return 0; }
+
+ BRNAME=`grep '^[ ]*lxc.network.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'`
+ if [ -z "$BRNAME" ]; then
+ return 0
+ fi
+
+ for try in `seq 1 30`; do
+ eval $cmd |grep "^$BRNAME" >/dev/null 2>&1
+ if [ $? = 0 ]; then
+ return
+ fi
+ sleep 1
+ done
+}
+
+# See how we were called.
+case "$1" in
+ start)
+ [ ! -f "$localstatedir"/lock/subsys/lxc ] || { exit 0; }
+
+ if [ -n "$BOOTGROUPS" ]
+ then
+ BOOTGROUPS="-g $BOOTGROUPS"
+ fi
+
+ # Start containers
+ ## wait_for_bridge
+ # Start autoboot containers first then the NULL group "onboot,".
+ ## action $"Starting LXC autoboot containers: " /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS
+ ## msg_starting lxc
+ ## echo "DEBUG: Launch: /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS"
+ CONTAINERS_LIST=`/usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS --list`
+ ## CONTAINERS_LIST=`/usr/bin/lxc-autostart --list`
+ ## echo "DEBUG: CONTAINERS_LIST:$CONTAINERS_LIST"
+
+ run_cmd "Starting LXC containers ( $CONTAINERS_LIST ) from groups: $BOOTGROUPS " /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS
+
+ touch "$localstatedir"/lock/subsys/lxc
+ ;;
+ stop)
+ if [ -n "$SHUTDOWNDELAY" ]
+ then
+ SHUTDOWNDELAY="-t $SHUTDOWNDELAY"
+ fi
+
+ # The stop is serialized and can take excessive time. We need to avoid
+ # delaying the system shutdown / reboot as much as we can since it's not
+ # parallelized... Even 5 second timout may be too long.
+ ## action $"Stopping LXC containers: " "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
+ CONTAINERS_LIST=`/usr/bin/lxc-autostart $STOPOPTS --list`
+
+ ## run_cmd "Stopping LXC containsers (CONTAINERS_LIST) from groups BOOTGROUPS " "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
+ run_cmd "Stopping running LXC containers ($CONTAINERS_LIST) " "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
+
+ rm -f "$localstatedir"/lock/subsys/lxc
+ ;;
+ restart|reload|force-reload)
+ $0 stop
+ $0 start
+ ;;
+ status)
+ lxc-ls --fancy # NOTE: python3-lxc is needed for lxc-ls
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|restart|reload|force-reload}"
+ exit 2
+esac
+exit $?
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/lxc.git/commitdiff/4d6732e1a21bc9177a9b4567666df39cd7a30f46
More information about the pld-cvs-commit
mailing list