~tribaal/+junk/landscape-client-14.12-0ubuntu1.15.04

« back to all changes in this revision

Viewing changes to debian/landscape-client.init

  • Committer: Chris Glass
  • Date: 2014-12-12 15:02:18 UTC
  • Revision ID: chris.glass@canonical.com-20141212150218-pryod8v4nr262b00
Initial import of released debian/ subdir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
### BEGIN INIT INFO
 
4
# Provides: landscape-client
 
5
# Required-Start: $local_fs $remote_fs
 
6
# Required-Stop: $local_fs $remote_fs
 
7
# Default-Start: 2 3 4 5
 
8
# Default-Stop: 0 1 6
 
9
# Short-Description: Landscape client daemons
 
10
# Description: The Landscape client daemons are needed so the
 
11
#              Landscape server can manage a computer.
 
12
### END INIT INFO
 
13
 
 
14
LANDSCAPE_DEFAULTS=/etc/default/landscape-client
 
15
NAME=landscape-client
 
16
DAEMON=/usr/bin/$NAME
 
17
PIDDIR=/var/run/landscape
 
18
SOCKETDIR=/var/lib/landscape/client/sockets
 
19
PIDFILE=$PIDDIR/$NAME.pid
 
20
RUN=0 # overridden in /etc/default/landscape-client
 
21
CLOUD=0 # overridden in /etc/default/landscape-client
 
22
DAEMON_GROUP=landscape
 
23
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
 
24
 
 
25
[ -f $DAEMON ] || exit 0
 
26
 
 
27
. /lib/lsb/init-functions
 
28
[ -f $LANDSCAPE_DEFAULTS ] && . $LANDSCAPE_DEFAULTS
 
29
 
 
30
check_config () {
 
31
    # This $RUN check should match the semantics of
 
32
    # l.sysvconfig.SysVConfig.is_configured_to_run.
 
33
    if [ $RUN -eq 0 ]; then
 
34
        echo "$NAME is not configured, please run landscape-config."
 
35
        exit 0
 
36
    fi
 
37
}
 
38
 
 
39
case "$1" in
 
40
        start)
 
41
                check_config
 
42
                log_daemon_msg "Starting the $NAME daemon"
 
43
                if [ ! -e $PIDDIR ]; then
 
44
                        mkdir $PIDDIR
 
45
                        chown landscape $PIDDIR
 
46
                fi
 
47
                # Cleanup leftover sockets if there's no other landscape process
 
48
                # running. This shouldn't be usually necessary, but it can
 
49
                # happen in case the client crashed badly and the socket points
 
50
                # to a process with the same PID.
 
51
                if [ -d "${SOCKETDIR:?}" ]; then
 
52
                        if ! pidofproc -p "$PIDFILE" "$DAEMON" > /dev/null; then
 
53
                                find "${SOCKETDIR:?}" -maxdepth 1 -type s -print0 | xargs -r0 rm -f
 
54
                                find "${SOCKETDIR:?}" -maxdepth 1 -type l -print0 | xargs -r0 rm -f
 
55
                        fi
 
56
                fi
 
57
 
 
58
                FULL_COMMAND="start-stop-daemon --start --quiet --oknodo --startas $DAEMON --pidfile $PIDFILE -g $DAEMON_GROUP -- --daemon --pid-file $PIDFILE"
 
59
                if [ x"$DAEMON_USER" != x ]; then
 
60
                        sudo -u $DAEMON_USER $FULL_COMMAND
 
61
                else
 
62
                        $FULL_COMMAND
 
63
                fi
 
64
                log_end_msg $?
 
65
                ;;
 
66
 
 
67
        stop)
 
68
                log_daemon_msg "Stopping $NAME daemon"
 
69
                start-stop-daemon --retry 30 --stop --quiet --pidfile $PIDFILE
 
70
                log_end_msg $?
 
71
                ;;
 
72
 
 
73
        status)
 
74
                # We want to maintain backward compatibility with Dapper,
 
75
                # so we're not going to use status_of_proc()
 
76
                pidofproc -p $PIDFILE $DAEMON >/dev/null
 
77
                status=$?
 
78
                if [ $status -eq 0 ]; then
 
79
                        log_success_msg "$NAME is running"
 
80
                else
 
81
                        log_failure_msg "$NAME is not running"
 
82
                fi
 
83
                exit $status
 
84
                ;;
 
85
 
 
86
        restart|force-reload)
 
87
                $0 stop && $0 start
 
88
                ;;
 
89
 
 
90
        *)
 
91
                echo "Usage: $0 {start|stop|status|restart|force-reload}"
 
92
                exit 1
 
93
                ;;
 
94
esac
 
95
 
 
96
exit 0