| 1 |
#! /bin/sh |
|---|
| 2 |
### BEGIN INIT INFO |
|---|
| 3 |
# Provides: ttrss |
|---|
| 4 |
# Required-Start: $local_fs $remote_fs mysql |
|---|
| 5 |
# Required-Stop: $local_fs $remote_fs |
|---|
| 6 |
# Default-Start: 2 3 4 5 |
|---|
| 7 |
# Default-Stop: 0 1 6 |
|---|
| 8 |
# Short-Description: Tiny Tiny RSS update daemon |
|---|
| 9 |
# Description: Update the Tiny Tiny RSS subscribed syndication feeds. |
|---|
| 10 |
### END INIT INFO |
|---|
| 11 |
|
|---|
| 12 |
# Author: Pierre-Yves Landurц╘ <pierre-yves@landure.org> |
|---|
| 13 |
|
|---|
| 14 |
# Do NOT "set -e" |
|---|
| 15 |
|
|---|
| 16 |
# PATH should only include /usr/* if it runs after the mountnfs.sh script |
|---|
| 17 |
PATH=/sbin:/usr/sbin:/bin:/usr/bin |
|---|
| 18 |
DESC="Tiny Tiny RSS update daemon" |
|---|
| 19 |
NAME=tt-rss |
|---|
| 20 |
DISABLED=0 |
|---|
| 21 |
FORKING=0 |
|---|
| 22 |
|
|---|
| 23 |
# Read configuration variable file if it is present |
|---|
| 24 |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
|---|
| 25 |
|
|---|
| 26 |
DAEMON_SCRIPT="update_daemon.php" |
|---|
| 27 |
|
|---|
| 28 |
if [ "$FORKING" != "0" ]; then |
|---|
| 29 |
DAEMON_SCRIPT="update_daemon2.php" |
|---|
| 30 |
fi |
|---|
| 31 |
|
|---|
| 32 |
DAEMON=/usr/bin/php |
|---|
| 33 |
DAEMON_ARGS="$TTRSS_PATH/$DAEMON_SCRIPT" |
|---|
| 34 |
DAEMON_DIR="$TTRSS_PATH" |
|---|
| 35 |
PIDFILE=/var/run/tt-rss.pid |
|---|
| 36 |
SCRIPTNAME=/etc/init.d/tt-rss |
|---|
| 37 |
|
|---|
| 38 |
# Exit if the package is not installed |
|---|
| 39 |
[ -x "$DAEMON" ] || exit 0 |
|---|
| 40 |
|
|---|
| 41 |
# Load the VERBOSE setting and other rcS variables |
|---|
| 42 |
. /lib/init/vars.sh |
|---|
| 43 |
|
|---|
| 44 |
# Define LSB log_* functions. |
|---|
| 45 |
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
|---|
| 46 |
. /lib/lsb/init-functions |
|---|
| 47 |
|
|---|
| 48 |
if [ "$DISABLED" != "0" -a "$1" != "stop" ]; then |
|---|
| 49 |
log_warning_msg "Not starting $DESC - edit /etc/default/tt-rss and change DISABLED to be 0."; |
|---|
| 50 |
exit 0; |
|---|
| 51 |
fi |
|---|
| 52 |
|
|---|
| 53 |
# |
|---|
| 54 |
# Function that starts the daemon/service |
|---|
| 55 |
# |
|---|
| 56 |
do_start() |
|---|
| 57 |
{ |
|---|
| 58 |
# Return |
|---|
| 59 |
# 0 if daemon has been started |
|---|
| 60 |
# 1 if daemon was already running |
|---|
| 61 |
# 2 if daemon could not be started |
|---|
| 62 |
start-stop-daemon --start --make-pidfile --background --quiet --chdir "$DAEMON_DIR" --pidfile "$PIDFILE" --exec "$DAEMON" --test > /dev/null \ |
|---|
| 63 |
|| return 1 |
|---|
| 64 |
|
|---|
| 65 |
start-stop-daemon --start --make-pidfile --background --quiet --chdir "$DAEMON_DIR" --pidfile "$PIDFILE" --exec "$DAEMON" -- \ |
|---|
| 66 |
$DAEMON_ARGS \ |
|---|
| 67 |
|| return 2 |
|---|
| 68 |
# Add code here, if necessary, that waits for the process to be ready |
|---|
| 69 |
# to handle requests from services started subsequently which depend |
|---|
| 70 |
# on this one. As a last resort, sleep for some time. |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
# |
|---|
| 74 |
# Function that stops the daemon/service |
|---|
| 75 |
# |
|---|
| 76 |
do_stop() |
|---|
| 77 |
{ |
|---|
| 78 |
# Return |
|---|
| 79 |
# 0 if daemon has been stopped |
|---|
| 80 |
# 1 if daemon was already stopped |
|---|
| 81 |
# 2 if daemon could not be stopped |
|---|
| 82 |
# other if a failure occurred |
|---|
| 83 |
start-stop-daemon --stop --make-pidfile --quiet --retry=TERM/1/KILL/5 --pidfile $PIDFILE --name $NAME |
|---|
| 84 |
RETVAL="$?" |
|---|
| 85 |
[ "$RETVAL" = 2 ] && return 2 |
|---|
| 86 |
# Wait for children to finish too if this is a daemon that forks |
|---|
| 87 |
# and if the daemon is only ever run from this initscript. |
|---|
| 88 |
# If the above conditions are not satisfied then add some other code |
|---|
| 89 |
# that waits for the process to drop all resources that could be |
|---|
| 90 |
# needed by services started subsequently. A last resort is to |
|---|
| 91 |
# sleep for some time. |
|---|
| 92 |
start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON |
|---|
| 93 |
[ "$?" = 2 ] && return 2 |
|---|
| 94 |
# Many daemons don't delete their pidfiles when they exit. |
|---|
| 95 |
rm -f $PIDFILE |
|---|
| 96 |
return "$RETVAL" |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
case "$1" in |
|---|
| 101 |
start) |
|---|
| 102 |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
|---|
| 103 |
do_start |
|---|
| 104 |
case "$?" in |
|---|
| 105 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
|---|
| 106 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
|---|
| 107 |
esac |
|---|
| 108 |
;; |
|---|
| 109 |
stop) |
|---|
| 110 |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
|---|
| 111 |
do_stop |
|---|
| 112 |
case "$?" in |
|---|
| 113 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
|---|
| 114 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
|---|
| 115 |
esac |
|---|
| 116 |
;; |
|---|
| 117 |
restart|force-reload) |
|---|
| 118 |
# |
|---|
| 119 |
# If the "reload" option is implemented then remove the |
|---|
| 120 |
# 'force-reload' alias |
|---|
| 121 |
# |
|---|
| 122 |
log_daemon_msg "Restarting $DESC" "$NAME" |
|---|
| 123 |
do_stop |
|---|
| 124 |
case "$?" in |
|---|
| 125 |
0|1) |
|---|
| 126 |
do_start |
|---|
| 127 |
case "$?" in |
|---|
| 128 |
0) log_end_msg 0 ;; |
|---|
| 129 |
1) log_end_msg 1 ;; # Old process is still running |
|---|
| 130 |
*) log_end_msg 1 ;; # Failed to start |
|---|
| 131 |
esac |
|---|
| 132 |
;; |
|---|
| 133 |
*) |
|---|
| 134 |
# Failed to stop |
|---|
| 135 |
log_end_msg 1 |
|---|
| 136 |
;; |
|---|
| 137 |
esac |
|---|
| 138 |
;; |
|---|
| 139 |
*) |
|---|
| 140 |
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
|---|
| 141 |
exit 3 |
|---|
| 142 |
;; |
|---|
| 143 |
esac |
|---|
| 144 |
|
|---|
| 145 |
: |
|---|