~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/tt-rss

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