Gentoo Archives: gentoo-commits

From: "Diego Petteno (flameeyes)" <flameeyes@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-emulation/lxc/files: lxc.initd
Date: Sun, 01 Aug 2010 04:02:16
Message-Id: 20100801031752.1C9EB2CF37@corvid.gentoo.org
1 flameeyes 10/08/01 03:17:51
2
3 Added: lxc.initd
4 Log:
5 Version bump, add the long-requested init script (protected with a USE=vanilla for those preferring not to have it).
6 (Portage version: 2.2_rc67/cvs/Linux x86_64)
7
8 Revision Changes Path
9 1.1 app-emulation/lxc/files/lxc.initd
10
11 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/lxc/files/lxc.initd?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/lxc/files/lxc.initd?rev=1.1&content-type=text/plain
13
14 Index: lxc.initd
15 ===================================================================
16 #!/sbin/runscript
17 # Copyright 1999-2010 Gentoo Foundation
18 # Distributed under the terms of the GNU General Public License v2
19 # $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/files/lxc.initd,v 1.1 2010/08/01 03:17:51 flameeyes Exp $
20
21 CONTAINER=${SVCNAME#*.}
22 CONFIGFILE=${CONFIGFILE:-/etc/lxc/${CONTAINER}.conf}
23
24 depend() {
25 need net.lo localmount
26 }
27
28 checkconfig() {
29 if [ ${CONTAINER} = ${SVCNAME} ]; then
30 eerror "You have to create an init script for each container:"
31 eerror " ln -s lxc /etc/init.d/lxc.container"
32 return 1
33 fi
34 }
35
36 rootpath() {
37 sed -n -e 's:^[ \t]*lxc.rootfs[ \t]*=[ \t]*\(.*\)$:\1:p' ${CONFIGFILE}
38 }
39
40 start() {
41 checkconfig || return 1
42
43 rm /var/log/lxc/${CONTAINER}.log
44
45 # Check the format of our init and the chroot's init, to see if we
46 # have to use linux32 or linux64…
47 case $(scanelf -BF '%M#f' /sbin/init $(rootpath)/sbin/init | tr '\n' ':') in
48 ELFCLASS64:ELFCLASS64:) setarch=;;
49 ELFCLASS32:ELFCLASS32:) setarch=;;
50 ELFCLASS32:ELFCLASS64:) setarch=linux64;;
51 ELFCLASS64:ELFCLASS32:) setarch=linux32;;
52 esac
53
54 mkdir -p /var/log/lxc
55
56 ebegin "Starting ${CONTAINER}"
57 ${setarch} lxc-start -n ${CONTAINER} -f ${CONFIGFILE} -d -o /var/log/lxc/${CONTAINER}.log
58 eend $?
59 }
60
61 stop() {
62 checkconfig || return 1
63
64 local init_pid=$(head -n1 /cgroup/${CONTAINER}/tasks)
65
66 ebegin "Shutting down system in ${CONTAINER}"
67 kill -INT ${init_pid}
68 eend $?
69
70 sleep 15
71
72 missingprocs=$(pgrep -P ${init_pid})
73
74 if [ -n "${missingprocs}" ]; then
75 ewarn "Something failed to properly shut down in ${CONTAINER}"
76 fi
77
78 ebegin "Stopping ${CONTAINER}"
79 lxc-stop -n ${CONTAINER}
80 eend $?
81 }