~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/cgmanager

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
### BEGIN INIT INFO
 
3
# Provides:          cgmanager
 
4
# Required-Start:    mountkernfs
 
5
# Required-Stop:     
 
6
# Default-Start:    2 3 4 5
 
7
# Default-Stop:     0 1 6
 
8
# Short-Description: Cgroup manager daemon
 
9
# Description:
 
10
#  The cgroup manager accepts cgroup administration requests
 
11
#  over dbus, honoring privilege by root users in mapped user
 
12
#  namespaces over the non-root mapped uids.  This allows safe
 
13
#  nesting of lxc containers by unprivileged users.
 
14
### END INIT INFO
 
15
 
 
16
# Do NOT "set -e"
 
17
 
 
18
PATH=/sbin:/bin
 
19
 
 
20
DAEMON=/sbin/cgmanager
 
21
NAME=cgmanager
 
22
DESC="cgroup management daemon"
 
23
 
 
24
BASEOPTS="--daemon -m name=systemd"
 
25
 
 
26
test -x $DAEMON || exit 0
 
27
 
 
28
PIDFILE=/run/$NAME.pid
 
29
 
 
30
if [ -f /etc/default/cgmanager ]; then
 
31
        # get cgmanager_opts if specified
 
32
        . /etc/default/cgmanager
 
33
fi
 
34
 
 
35
# Load the VERBOSE setting and other rcS variables
 
36
. /lib/init/vars.sh
 
37
 
 
38
# Define LSB log_* functions.
 
39
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
 
40
# and status_of_proc is working.
 
41
. /lib/lsb/init-functions
 
42
 
 
43
DAEMON_ARGS="$BASEOPTS $cgmanager_opts $cgm_extra_mounts"
 
44
 
 
45
do_stop()
 
46
{
 
47
        # If the cgmanager stops, the proxy must stop
 
48
        /etc/init.d/cgproxy stop >/dev/null 2>&1 || true
 
49
        # Return
 
50
        #   0 if daemon has been stopped
 
51
        #   1 if daemon was already stopped
 
52
        #   2 if daemon could not be stopped
 
53
        #   other if a failure occurred
 
54
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
 
55
        RETVAL="$?"
 
56
        [ "$RETVAL" = 2 ] && return 2
 
57
        # Wait for children to finish too if this is a daemon that forks
 
58
        # and if the daemon is only ever run from this initscript.
 
59
        # If the above conditions are not satisfied then add some other code
 
60
        # that waits for the process to drop all resources that could be
 
61
        # needed by services started subsequently.  A last resort is to
 
62
        # sleep for some time.
 
63
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
 
64
        [ "$?" = 2 ] && return 2
 
65
        # Many daemons don't delete their pidfiles when they exit.
 
66
        rm -f $PIDFILE
 
67
        return "$RETVAL"
 
68
}
 
69
 
 
70
do_start()
 
71
{
 
72
        # Return
 
73
        #   0 if daemon has been started
 
74
        #   1 if daemon was already running
 
75
        #   2 if daemon could not be started
 
76
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
 
77
                || return 1
 
78
 
 
79
        # Kill any existing cgproxy
 
80
        /etc/init.d/cgproxy stop >/dev/null 2>&1 || true
 
81
        # check whether to start cgproxy or cgmanager
 
82
        if /sbin/cgproxy --check-master; then
 
83
                NESTED=yes /etc/init.d/cgproxy start || true && { exit 0; }
 
84
        fi
 
85
 
 
86
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
 
87
                $DAEMON_ARGS \
 
88
                || return $?
 
89
        # Todo - once the compiled cgm is installed we could use it here to ping
 
90
        # cgmanager as our test for readiness.
 
91
        sleep 1
 
92
}
 
93
 
 
94
case "$1" in
 
95
    restart|force-reload)
 
96
        log_daemon_msg "Restarting $DESC" "$NAME"
 
97
        do_stop
 
98
        case "$?" in
 
99
          0|1)
 
100
                do_start
 
101
                case "$?" in
 
102
                        0) log_end_msg 0 ;;
 
103
                        1) log_end_msg 1 ;; # Old process is still running
 
104
                        *) log_end_msg 1 ;; # Failed to start
 
105
                esac
 
106
                ;;
 
107
          *)
 
108
                # Failed to stop
 
109
                log_end_msg 1
 
110
                ;;
 
111
        esac
 
112
        ;;
 
113
    start)
 
114
        log_daemon_msg "Starting $DESC" "$NAME"
 
115
        do_start
 
116
        case "$?" in
 
117
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
118
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
119
        esac
 
120
        ;;
 
121
  stop)
 
122
        log_daemon_msg "Stopping $DESC" "$NAME"
 
123
        do_stop
 
124
        case "$?" in
 
125
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
126
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
127
        esac
 
128
        ;;
 
129
  status)
 
130
        status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
 
131
        ;;
 
132
  *)
 
133
        echo "Usage: $0 {start|stop|restart|force-reload}" >&2
 
134
        exit 3
 
135
        ;;
 
136
esac
 
137
 
 
138
: