mirror_lxc/config/init/sysvinit/lxc
Stéphane Graber dc0682900a init: Add upstart jobs and some more changes (v3)
This adds the 3 upstart jobs that we've had in Ubuntu for a while:
 - lxc.conf: Main upstart job, triggers lxc-net.conf based on config
 - lxc-instance.conf: Triggered by lxc.conf for each auto-started container
 - lxc-net.conf: Triggered by lxc.conf, sets up lxcbr0, NAT, mangling, ...

In addition, there are two extra config files in /etc/default:
 - lxc: Allows setting some values like http proxying, disabling autostart, ...
 - lxc-net: Network configuration for the lxcbr0 bridge

This change also disables the sysv script for all distros but Oracle as
the current script won't work on either Ubuntu nor Debian and I suspect
quite a few more distros, so it's not nearly as distro-agnostic as we
thought.

For Debian, only install the upstart jobs and systemd unit.
For Ubuntu, only install the upstart jobs.

This change also moves all the init related stuff to config/init/

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-01-16 17:18:38 -05:00

65 lines
1.4 KiB
Bash
Executable File

#!/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
# Source function library.
. /etc/init.d/functions
# Check for needed utility program
[ -x /usr/bin/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 /etc/lxc/default.conf ] || { return 0; }
BRNAME=`grep lxc.network.link /etc/lxc/default.conf |awk '{print $3}'`
[ -n $BRNAME ] || { return 0; }
for try in `seq 1 30`; do
ifconfig -a |grep "^$BRNAME" >/dev/null 2>&1
if [ $? = 0 ]; then
return
fi
sleep 1
done
}
# See how we were called.
case "$1" in
start)
[ ! -f /var/lock/subsys/lxc ] || { exit 0; }
# Start containers
wait_for_bridge
action $"Starting LXC containers: " /usr/bin/lxc-autostart
touch /var/lock/subsys/lxc
;;
stop)
action $"Stopping LXC containers: " /usr/bin/lxc-autostart -s
rm -f /var/lock/subsys/lxc
;;
restart|reload|force-reload)
$0 stop
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|force-reload}"
exit 2
esac
exit $?