~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/ifetch-tools

  • 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
 
 
3
 
### BEGIN INIT INFO
4
 
# Provides:             ifetch-tools
5
 
# Required-Start:       $remote_fs $network $syslog
6
 
# Required-Stop:        $remote_fs $network $syslog
7
 
# Should-Start:         $local_fs
8
 
# Default-Start:        2 3 4 5
9
 
# Default-Stop:         0 1 6
10
 
# Short-Description:    Tools to collect IP Camera images.
11
 
# Description:          Tools to collect, monitor, view images from IP Cameras.
12
 
### END INIT INFO
13
 
set -e
14
 
 
15
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
16
 
DAEMON=/usr/bin/wwwifetch
17
 
DAEMON_CONFIG=/etc/ifetch-tools/ifetch-tools.conf
18
 
NAME=ifetch-tools
19
 
DESC=ifetch-tools
20
 
_UID=ifetch-tools
21
 
#_UID=root
22
 
 
23
 
# Test the the DAEMON
24
 
test -x $DAEMON || exit 0
25
 
 
26
 
# Test for the ifetch-tools.conf
27
 
test -f $DAEMON_CONFIG || exit 0
28
 
 
29
 
. /lib/lsb/init-functions
30
 
 
31
 
LOGDIR=/var/log/ifetch-tools
32
 
PIDFILE=/var/run/$NAME.pid
33
 
DODTIME=10      # Time to wait for the server to die, in seconds
34
 
                # If this value is set too low you might not
35
 
                # let some servers to die gracefully and
36
 
                # 'restart' will not work
37
 
 
38
 
running_pid()
39
 
{
40
 
        # Check if a given process pid's cmdline matches a given name
41
 
        pid=$1
42
 
        name=$2
43
 
 
44
 
        [ -z "$pid" ] && return 1
45
 
 
46
 
        [ ! -d /proc/$pid ] &&  return 1
47
 
 
48
 
        cmd=$(cat /proc/$pid/cmdline | tr "\000" "\n"|tail -n 1 |cut -d : -f 1)
49
 
 
50
 
        # Is this the expected child?
51
 
        [ "$cmd" != "$name" ] &&  return 1
52
 
 
53
 
        return 0
54
 
}
55
 
 
56
 
running()
57
 
{
58
 
        # Check if the process is running looking at /proc
59
 
        # (works for all users)
60
 
 
61
 
        # No pidfile, probably no daemon present
62
 
        [ ! -f "$PIDFILE" ] && return 1
63
 
 
64
 
        # Obtain the pid and check it against the binary name
65
 
        pid=$(cat $PIDFILE)
66
 
        running_pid $pid $DAEMON || return 1
67
 
 
68
 
        return 0
69
 
}
70
 
 
71
 
start_daemon()
72
 
{
73
 
        echo -n "Starting $DESC: "
74
 
        start-stop-daemon --start --chdir /tmp --nicelevel 10 --chuid $_UID --quiet --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON
75
 
 
76
 
        [ -n "$DODTIME" ] && sleep "$DODTIME"s
77
 
        echo -n "$NAME, "
78
 
 
79
 
        if running
80
 
        then
81
 
                echo "appears to be started."
82
 
        else
83
 
                echo "appears to have failed to start."
84
 
                exit 0
85
 
        fi
86
 
}
87
 
 
88
 
stop_daemon()
89
 
{
90
 
        signal=$1
91
 
 
92
 
        echo -n "Stopping $DESC: "
93
 
        kill -s $signal $(pgrep -u $_UID ifetch)
94
 
 
95
 
        [ -n "$DODTIME" ] && sleep "$DODTIME"s
96
 
 
97
 
        if running
98
 
        then
99
 
                echo "Cannot stop $NAME!"
100
 
                exit 1
101
 
        else
102
 
                echo "$NAME stopped."
103
 
                rm -f $PIDFILE
104
 
        fi
105
 
 
106
 
        return 0
107
 
}
108
 
 
109
 
case "$1" in
110
 
        start)
111
 
                mkdir -p /var/run/ifetch-tools
112
 
                mkdir -p /var/lock/ifetch-tools
113
 
                chown ifetch-tools:ifetch-tools /var/run/ifetch-tools /var/lock/ifetch-tools
114
 
                if running
115
 
                then
116
 
                        echo "$NAME appears to be already running."
117
 
                else
118
 
                        start_daemon
119
 
                fi
120
 
                ;;
121
 
 
122
 
        stop)
123
 
                if running
124
 
                then
125
 
                        stop_daemon INT
126
 
                else
127
 
                        echo "$NAME is not running."
128
 
                fi
129
 
                ;;
130
 
 
131
 
        force-stop)
132
 
                if running
133
 
                then
134
 
                        echo "Forcefully stopping $DESC and camera collecting."
135
 
                        stop_daemon KILL
136
 
                else
137
 
                        echo "$NAME is not running."
138
 
                fi
139
 
                ;;
140
 
 
141
 
        reload)
142
 
                stop_daemon INT
143
 
                start_daemon
144
 
                ;;
145
 
 
146
 
        force-reload)
147
 
                if running
148
 
                then
149
 
                        echo "Forcefully reloading $DESC and camera collecting."
150
 
                        stop_daemon KILL
151
 
                        start_daemon
152
 
                else
153
 
                        echo "$NAME is not running."
154
 
                fi
155
 
                ;;
156
 
 
157
 
        restart)
158
 
                echo "Restarting $DESC."
159
 
 
160
 
                if running
161
 
                then
162
 
                        stop_daemon INT
163
 
                        start_daemon
164
 
                else
165
 
                        echo "No running process, try start."
166
 
                fi
167
 
                ;;
168
 
 
169
 
        status)
170
 
                echo -n "$NAME is "
171
 
 
172
 
                if running
173
 
                then
174
 
                        echo "running."
175
 
                else
176
 
                        echo "not running."
177
 
                        exit 1
178
 
                fi
179
 
                ;;
180
 
 
181
 
        *)
182
 
                N=/etc/init.d/$NAME
183
 
                echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2
184
 
                exit 1
185
 
                ;;
186
 
esac
187
 
 
188
 
exit 0