~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

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

  • 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:          ziproxy
 
4
# Required-Start:    $remote_fs $network
 
5
# Required-Stop:     $remote_fs $network 
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      0 1 6
 
8
# Short-Description: Init script for ziproxy
 
9
# Description:       This is the init script for ziproxy.
 
10
### END INIT INFO
 
11
 
 
12
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
13
DAEMON=/usr/bin/ziproxy
 
14
NAME=ziproxy
 
15
DESC=ziproxy
 
16
 
 
17
test -x $DAEMON || exit 0
 
18
 
 
19
PIDFILE=/var/run/$NAME.pid
 
20
DODTIME=1                   # Time to wait for the server to die, in seconds
 
21
                            # If this value is set too low you might not
 
22
                            # let some servers to die gracefully and
 
23
                            # 'restart' will not work
 
24
 
 
25
if [ ! -d /var/run ]; then
 
26
        mkdir -p /var/run
 
27
fi
 
28
 
 
29
# Include ziproxy defaults if available
 
30
if [ -f /etc/default/ziproxy ] ; then
 
31
        . /etc/default/ziproxy
 
32
fi
 
33
DAEMON_OPTS="$DAEMON_OPTS -d -p $PIDFILE"
 
34
 
 
35
set -e
 
36
 
 
37
running_pid() {
 
38
    # Check if a given process pid's cmdline matches a given name
 
39
    pid=$1
 
40
    name=$2
 
41
    [ -z "$pid" ] && return 1 
 
42
    [ ! -d /proc/$pid ] &&  return 1
 
43
    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
 
44
    # Is this the expected child?
 
45
    ##[ "$cmd" != "$name" ] &&  return 1
 
46
    [ "$cmd" != "$name" ] &&  return 1
 
47
    return 0
 
48
}
 
49
 
 
50
running() {
 
51
# Check if the process is running looking at /proc
 
52
# (works for all users)
 
53
 
 
54
    # No pidfile, probably no daemon present
 
55
    [ ! -f "$PIDFILE" ] && return 1
 
56
    # Obtain the pid and check it against the binary name
 
57
    pid=`cat $PIDFILE`
 
58
    if ! running_pid $pid $DAEMON; then
 
59
        rm $PIDFILE
 
60
        return 1
 
61
    fi
 
62
    return 0
 
63
}
 
64
 
 
65
force_stop() {
 
66
# Forcefully kill the process
 
67
    [ ! -f "$PIDFILE" ] && return
 
68
    if running ; then
 
69
        kill -15 $pid
 
70
        # Is it really dead?
 
71
        [ -n "$DODTIME" ] && sleep "$DODTIME"s
 
72
        if running ; then
 
73
            kill -9 $pid
 
74
            [ -n "$DODTIME" ] && sleep "$DODTIME"s
 
75
            if running ; then
 
76
                echo "Cannot kill $NAME (pid=$pid)!"
 
77
                exit 1
 
78
            fi
 
79
        fi
 
80
    fi
 
81
    rm -f $PIDFILE
 
82
    return 0
 
83
}
 
84
 
 
85
is_not_running() {
 
86
    if ! running; then
 
87
        echo "$NAME is not running."
 
88
        exit 1
 
89
    fi
 
90
}
 
91
 
 
92
do_start() {
 
93
    off_echo=$1
 
94
 
 
95
    [ $off_echo ] || echo -n "Starting $DESC: "
 
96
    if running; then
 
97
        echo "$NAME is already running."
 
98
        exit 0
 
99
    fi  
 
100
    start-stop-daemon --start --quiet --pidfile $PIDFILE \
 
101
        --exec $DAEMON -- $DAEMON_OPTS
 
102
    if running; then
 
103
        [ $off_echo ] || echo "$NAME."
 
104
    else
 
105
        echo " ERROR."
 
106
    fi
 
107
}
 
108
 
 
109
do_stop() {
 
110
    off_echo=$1
 
111
 
 
112
    [ $off_echo ] || echo -n "Stopping $DESC: "
 
113
    start-stop-daemon --stop --quiet --pidfile $PIDFILE \
 
114
        --exec $DAEMON
 
115
    [ -f $PIDFILE ] && rm $PIDFILE
 
116
    [ $off_echo ] || echo "$NAME."
 
117
}
 
118
 
 
119
case "$1" in
 
120
    start)
 
121
        do_start
 
122
        ;;
 
123
    stop)
 
124
        do_stop
 
125
        ;;
 
126
    force-stop)
 
127
        echo -n "Forcefully stopping $DESC: "
 
128
        is_not_running
 
129
        force_stop
 
130
        if ! running; then
 
131
            echo "$NAME."
 
132
        else
 
133
            echo " ERROR."
 
134
        fi
 
135
        ;;
 
136
    restart|force-reload)
 
137
        echo -n "Restarting $DESC: "
 
138
        is_not_running
 
139
        do_stop 1
 
140
        [ -n "$DODTIME" ] && sleep $DODTIME
 
141
        do_start 1
 
142
        echo "$NAME."
 
143
        ;;
 
144
    status)
 
145
        echo -n "$NAME is "
 
146
        if running ;  then
 
147
            echo "running."
 
148
        else
 
149
            echo "not running."
 
150
            exit 1
 
151
        fi
 
152
        ;;
 
153
    *)
 
154
        N=/etc/init.d/$NAME
 
155
        echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2
 
156
        exit 1
 
157
        ;;
 
158
esac
 
159
 
 
160
exit 0