]> git.pld-linux.org Git - packages/lxd.git/blob - lxd.init
1ed4147deaeb7dc763c364c5f993942ad28f890c
[packages/lxd.git] / lxd.init
1 #!/bin/sh
2 #
3 # Container hypervisor and a new user experience for LXC
4 #
5 # chkconfig:    345 20 80
6 #
7 # processname:  lxd
8 # pidfile: /var/run/lxd.pid
9 #
10
11 # Source function library
12 . /etc/rc.d/init.d/functions
13
14 # Get network config
15 . /etc/sysconfig/network
16
17 # Check that networking is up.
18 if is_yes "${NETWORKING}"; then
19         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
20                 msg_network_down "lxd"
21                 exit 1
22         fi
23 else
24         exit 0
25 fi
26
27 # Get service config - may override defaults
28 [ -f /etc/sysconfig/lxd ] && . /etc/sysconfig/lxd
29 OPTIONS="$OPTIONS --group lxd --logfile /var/log/lxd/lxd.log"
30
31 pidfile="/var/run/lxd.pid"
32
33 start() {
34         if status --pidfile $pidfile lxd lxd >/dev/null; then
35                 msg_already_running "lxd"
36                 RETVAL=1
37                 return
38         fi
39                 
40         msg_starting "lxd"
41         daemon --fork --waitforname lxd /usr/lib/lxd-wrapper daemon $OPTIONS 
42         
43         # lxd does not write pidfile, so create one
44         show "Checking lxd daemon status"
45         busy
46         pid=""
47         ntry=0
48         while [ -z "$pid" -a $ntry -lt 5 ]; do
49                 [ -z "$pid" ] && sleep 1
50                 pid=$(lxc info 2>/dev/null | awk '/server_pid:/{print $2}')
51                 [ -n "$pid" ] && echo $pid > $pidfile
52                 ntry=$(($ntry+1))
53         done
54
55         if [ -n "$pid" ]; then
56                 touch /var/lock/subsys/lxd
57                 ok
58                 RETVAL=0
59         else
60                 fail
61                 RETVAL=1
62         fi
63 }
64
65 stop() {
66         if [ ! -f /var/lock/subsys/lxd ]; then
67                 msg_not_running "lxd"
68                 return
69         fi
70
71         # Stop daemons.
72         msg_stopping "lxd"
73         /usr/sbin/lxd shutdown 
74         busy
75         sleep 1
76         if status --pidfile $pidfile lxd lxd >/dev/null; then
77                 killproc --pidfile $pidfile lxd
78         else
79                 ok
80         fi
81         rm -f /var/lock/subsys/lxd
82 }
83
84 condrestart() {
85         if [ ! -f /var/lock/subsys/lxd ]; then
86                 msg_not_running "lxd"
87                 RETVAL=$1
88                 return
89         fi
90
91         stop
92         start
93 }
94
95 RETVAL=0
96 # See how we were called.
97 case "$1" in
98   start)
99         start
100         ;;
101   stop)
102         stop
103         ;;
104   restart)
105         stop
106         start
107         ;;
108   try-restart)
109         condrestart 0
110         ;;
111   force-reload)
112         condrestart 7
113         ;;
114   status)
115         status --pidfile $pidfile lxd lxd
116         RETVAL=$?
117         ;;
118   *)
119         msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
120         exit 3
121 esac
122
123 exit $RETVAL
This page took 0.059159 seconds and 2 git commands to generate.