~serge-hallyn/ubuntu/quantal/lxc/lxc-fixapi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh

### BEGIN INIT INFO
# Provides:		lxc
# Required-Start:	$syslog $remote_fs
# Required-Stop:	$syslog $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Linux Containers
# Description:		Linux Containers
# X-Start-Before:
# X-Stop-After:
# X-Interactive:	true
### END INIT INFO

if [ ! -x /usr/bin/lxc ]
then
	exit 0
fi

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

. /lib/lsb/init-functions

if [ -f /etc/default/lxc ]
then
	. /etc/default/lxc
fi

LXC_AUTO="${LXC_AUTO:-true}"

Lxc ()
{
	_PROGRAM="${@}"

	# no containers available
	if ! ls /etc/lxc/auto/* > /dev/null 2>&1
	then
		log_progress_msg "(none)"
		log_end_msg 0

		exit 0
	fi

	for _CONFIG in /etc/lxc/auto/*
	do
		_CONTAINER="$(basename ${_CONFIG})"

		if [ -L "${_CONFIG}" ] && [ ! -e "${_CONFIG}" ]
		then
			# dangling symlink
			log_progress_msg "${_CONTAINER} (broken)"

			continue
		fi

		case "${_PROGRAM}" in
			start)
				# initscript is disabled
				case "${LXC_AUTO}" in
					false)
						log_progress_msg "(disabled)"
						log_end_msg 0

						exit 0
						;;
				esac

				if ! lxc-info -n ${_CONTAINER} 2>&1 | grep -qs "RUNNING"
				then
					log_progress_msg "${_CONTAINER}"

					lxc-${_PROGRAM} -n ${_CONTAINER} -f ${_CONFIG} -d
				else
					log_progress_msg "${_CONTAINER} (skip)"
				fi
				;;

			*)
				log_progress_msg "${_CONTAINER}"

				lxc ${_PROGRAM} ${_CONTAINER}
				;;
		esac
	done

	log_end_msg 0
}

case "${1}" in
	start)
		log_daemon_msg "Starting Linux Containers"

		Lxc start
		;;

	stop)
		log_daemon_msg "Stopping Linux Containers"

		Lxc shutdown
		;;

	restart|force-reload)
		log_daemon_msg "Restarting Linux Containers"

		Lxc shutdown
		Lxc start
		;;

	freeze)
		log_daemon_msg "Freezing Linux Containers"

		Lxc freeze
		;;

	unfreeze)
		log_daemon_msg "Unfreezing Linux Containers"

		Lxc unfreeze
		;;

	status)
		lxc-list
		;;

	*)
		log_success_msg "Usage: ${0} {start|stop|restart|force-reload|freeze|unfreeze|status}"
		exit 1
		;;
esac

exit 0