275
by Francois Marier
Add a gearman worker script to delete photos |
1 |
#!/bin/sh
|
2 |
### BEGIN INIT INFO
|
|
3 |
# Provides: deletephoto
|
|
4 |
# Required-Start: $network $local_fs $remote_fs gearman-job-server
|
|
5 |
# Required-Stop: $remote_fs
|
|
6 |
# Default-Start: 2 3 4 5
|
|
7 |
# Default-Stop: 0 1 6
|
|
8 |
# Short-Description: Gearman worker for deleting files
|
|
9 |
# Description: Gearman worker for deleting files
|
|
10 |
### END INIT INFO
|
|
11 |
||
12 |
# Author: Francois Marier <francois@debian.org>
|
|
13 |
||
14 |
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
|
15 |
PATH=/sbin:/usr/sbin:/bin:/usr/bin |
|
16 |
DESC="Libravatar deletephoto worker" |
|
17 |
NAME=deletephoto |
|
18 |
PIDDIR=/var/run/libravatar |
|
19 |
PIDFILE=$PIDDIR/$NAME.pid |
|
20 |
DAEMON=/usr/bin/gearman |
|
21 |
DAEMON_ARGS="-w -i $PIDFILE -f deletephoto /usr/share/libravatar/libravatar/deletephoto.py" |
|
22 |
SCRIPTNAME=/etc/init.d/$NAME |
|
23 |
||
24 |
# Exit if the package is not installed
|
|
25 |
[ -x $DAEMON ] || exit 0 |
|
26 |
||
27 |
# Read configuration variable file if it is present
|
|
28 |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
|
29 |
||
30 |
# Load the VERBOSE setting and other rcS variables
|
|
31 |
. /lib/init/vars.sh |
|
32 |
||
33 |
# Define LSB log_* functions.
|
|
34 |
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
|
35 |
. /lib/lsb/init-functions |
|
36 |
||
37 |
#
|
|
38 |
# Function that starts the daemon/service
|
|
39 |
#
|
|
40 |
do_start()
|
|
41 |
{
|
|
278
by Francois Marier
Simplify the /var/run/libravatar creation and make sure cropresize can write to it |
42 |
mkdir -p ${PIDDIR} |
275
by Francois Marier
Add a gearman worker script to delete photos |
43 |
# Return
|
44 |
# 0 if daemon has been started
|
|
45 |
# 1 if daemon was already running
|
|
46 |
# 2 if daemon could not be started
|
|
47 |
start-stop-daemon --start --quiet --pidfile $PIDFILE --background --exec $DAEMON --test > /dev/null \ |
|
48 |
|| return 1 |
|
49 |
start-stop-daemon --start --quiet --pidfile $PIDFILE --background --exec $DAEMON -- \ |
|
50 |
$DAEMON_ARGS \ |
|
51 |
|| return 2 |
|
52 |
}
|
|
53 |
||
54 |
#
|
|
55 |
# Function that stops the daemon/service
|
|
56 |
#
|
|
57 |
do_stop()
|
|
58 |
{
|
|
59 |
# Return
|
|
60 |
# 0 if daemon has been stopped
|
|
61 |
# 1 if daemon was already stopped
|
|
62 |
# 2 if daemon could not be stopped
|
|
63 |
# other if a failure occurred
|
|
64 |
start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE |
|
65 |
RETVAL="$?" |
|
66 |
[ "$RETVAL" = 2 ] && return 2 |
|
67 |
rm -f $PIDFILE
|
|
68 |
return "$RETVAL" |
|
69 |
}
|
|
70 |
||
71 |
#
|
|
72 |
# Function that sends a SIGHUP to the daemon/service
|
|
73 |
#
|
|
74 |
do_reload() { |
|
75 |
#
|
|
76 |
# If the daemon can reload its configuration without
|
|
77 |
# restarting (for example, when it is sent a SIGHUP),
|
|
78 |
# then implement that here.
|
|
79 |
#
|
|
80 |
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME |
|
81 |
return 0 |
|
82 |
}
|
|
83 |
||
84 |
case "$1" in |
|
85 |
start)
|
|
86 |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME" |
|
87 |
do_start |
|
88 |
case "$?" in |
|
89 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
|
90 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
|
91 |
esac
|
|
92 |
;;
|
|
93 |
stop)
|
|
94 |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
|
95 |
do_stop |
|
96 |
case "$?" in |
|
97 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
|
98 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
|
99 |
esac
|
|
100 |
;;
|
|
101 |
status)
|
|
279
by Francois Marier
Fix the status detection for the gearman workers by looking at the PID |
102 |
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $? |
275
by Francois Marier
Add a gearman worker script to delete photos |
103 |
;;
|
104 |
restart|force-reload) |
|
105 |
log_daemon_msg "Restarting $DESC" "$NAME" |
|
106 |
do_stop |
|
107 |
case "$?" in |
|
108 |
0|1) |
|
109 |
do_start |
|
110 |
case "$?" in |
|
111 |
0) log_end_msg 0 ;; |
|
112 |
1) log_end_msg 1 ;; # Old process is still running |
|
113 |
*) log_end_msg 1 ;; # Failed to start |
|
114 |
esac
|
|
115 |
;;
|
|
116 |
*)
|
|
117 |
# Failed to stop
|
|
118 |
log_end_msg 1
|
|
119 |
;;
|
|
120 |
esac
|
|
121 |
;;
|
|
122 |
*)
|
|
123 |
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
|
124 |
exit 3 |
|
125 |
;;
|
|
126 |
esac
|
|
127 |
||
128 |
: |