Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ditch /etc/default/lxc file in favour of tagging containers to be sta…

…rted.

Now if you echo 1 > /var/lib/lxc/$CONTAINER/autostart, the lxc init
script will start it on boot.

Updated docs to reflect this too.
  • Loading branch information...
commit a4eb316b438f355d5c28c24f90d33c94da6b8769 1 parent d7cd69b
@nigelmcnie nigelmcnie authored
Showing with 32 additions and 29 deletions.
  1. +6 −3 README
  2. +26 −26 init
View
9 README
@@ -51,10 +51,13 @@ init
`init' is an init.d script you can install as /etc/init.d/lxc, that allows you
to automatically start up and shut down containers on system start up/shut
-down. To specify the containers to start and stop, put this into
-/etc/default/lxc:
+down.
-CONTAINERS="name1 name2 name3"
+You can mark a container to be started on startup by doing this:
+
+echo 1 > /var/lib/lxc/$CONTAINER/autostart
+
+All containers will be stopped on shutdown, regardless of the autostart file.
Note that this script will endeavour to use lxc-halt if it's in /usr/bin, see
the docs for lxc-halt below for more information.
View
52 init
@@ -21,28 +21,26 @@ SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x /usr/bin/lxc-start ] || exit 0
-# Read configuration variable file if it is present
-[ -r /etc/default/$NAME ] && . /etc/default/$NAME
-
-# Exit if there's no containers to start/stop
-[ ! -z "$CONTAINERS" ] || exit 0
-
. /lib/init/vars.sh
. /lib/lsb/init-functions
do_start()
{
- for C in $CONTAINERS; do
- log_progress_msg "$C"
- if lxc-info -n $C | grep STOPPED > /dev/null 2>&1; then
- if [ -x /usr/bin/screen ]; then
- /usr/bin/screen -dmS init-${C} /usr/bin/lxc-start -n $C
- else
- lxc-start -n $C -d
- fi
- lxc-wait -n $C -s RUNNING
- if [ $? -gt 0 ]; then
- return 2
+ for C in $(ls -1 /var/lib/lxc); do
+ if [ -r /var/lib/lxc/$C/autostart ]; then
+ if [ "$(cat /var/lib/lxc/$C/autostart)" = "1" ]; then
+ log_progress_msg "$C"
+ if lxc-info -n $C | grep STOPPED > /dev/null 2>&1; then
+ if [ -x /usr/bin/screen ]; then
+ /usr/bin/screen -dmS init-${C} /usr/bin/lxc-start -n $C
+ else
+ lxc-start -n $C -d
+ fi
+ lxc-wait -n $C -s RUNNING
+ if [ $? -gt 0 ]; then
+ return 2
+ fi
+ fi
fi
fi
done
@@ -51,15 +49,17 @@ do_start()
do_stop()
{
halt=$(which lxc-halt)
- for C in $CONTAINERS; do
- log_progress_msg "$C"
- if lxc-info -n $C | grep RUNNING > /dev/null 2>&1; then
- if [ -n "$halt" ]; then
- $halt -n $C &
- else
- /usr/bin/lxc-stop -n $C
- if [ $? -gt 0 ]; then
- return 2
+ for C in $(ls -1 /var/lib/lxc); do
+ if [ -f /var/lib/lxc/$C/state ]; then
+ log_progress_msg "$C"
+ if lxc-info -n $C | grep RUNNING > /dev/null 2>&1; then
+ if [ -n "$halt" ]; then
+ $halt -n $C &
+ else
+ /usr/bin/lxc-stop -n $C
+ if [ $? -gt 0 ]; then
+ return 2
+ fi
fi
fi
fi
Please sign in to comment.
Something went wrong with that request. Please try again.