source: lliurex-statistics/trunk/fuentes/lliurex-statistics.install/etc/init.d/analytics @ 2775

Last change on this file since 2775 was 2775, checked in by mabarracus, 3 years ago

Fix loop with systemd

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides:          analytics
4# Required-Start:    auditd
5# Required-Stop:     $local_fs
6# Default-Start:     2 3 4 5
7# Default-Stop:      0 1 6
8# Short-Description: Analytics Daemon
9# Description:       Collects analytics information.
10# X-Start-Before:    auditd
11# X-Stop-After:
12### END INIT INFO
13
14# Author: M.Angel Juan <m.angel.juan@gmail.com>
15
16PATH=/sbin:/usr/sbin:/bin:/usr/bin
17DESC="analytics daemon"
18NAME=analytics
19DAEMON=/usr/sbin/"$NAME"
20PIDFILE=/var/run/"$NAME".pid
21SCRIPTNAME=/etc/init.d/"$NAME"
22
23# Exit if the package is not installed
24[ -x "$DAEMON" ] || exit 0
25
26# Read configuration variable file if it is present
27[ -r /etc/lliurex-analytics/agent.cfg ] || exit 0
28
29# Define LSB log_* functions.
30. /lib/lsb/init-functions
31
32#
33# Function that starts the daemon/service
34#
35do_start()
36{
37        # Return
38        #   0 if daemon has been started
39        #   1 if daemon was already running
40        #   2 if daemon could not be started
41        start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" -- \
42                $EXTRAOPTIONS \
43                || return 2
44}
45
46#
47# Function that stops the daemon/service
48#
49do_stop()
50{
51        # Return
52        #   0 if daemon has been stopped
53        #   1 if daemon was already stopped
54        #   2 if daemon could not be stopped
55        #   other if a failure occurred
56        start-stop-daemon --stop --quiet --retry=INT/5/KILL/2 --pidfile "$PIDFILE" --name "$NAME"
57        RETVAL="$?"
58        [ "$RETVAL" = 2 ] && return 2
59        start-stop-daemon --stop --quiet --oknodo --retry=TERM/5/KILL/2 --exec "$DAEMON"
60        [ "$?" = 2 ] && return 2
61        # Many daemons don't delete their pidfiles when they exit.
62        rm -f "$PIDFILE"
63        return "$RETVAL"
64}
65
66#
67# Function that sends a SIGHUP to the daemon/service
68#
69do_reload() {
70        do_stop
71        do_start
72        return 0
73}
74
75case "$1" in
76  start)
77        log_daemon_msg "Starting $DESC" "$NAME"
78        do_start
79        case "$?" in
80                0|1) log_end_msg 0 ;;
81                2) log_end_msg 1 ;;
82        esac
83        ;;
84  stop)
85        log_daemon_msg "Stopping $DESC" "$NAME"
86        do_stop
87        case "$?" in
88                0|1) log_end_msg 0 ;;
89                2) log_end_msg 1 ;;
90        esac
91        ;;
92  reload|force-reload)
93        log_daemon_msg "Reloading $DESC" "$NAME"
94        do_reload
95        log_end_msg $?
96        ;;
97  restart)
98        log_daemon_msg "Restarting $DESC" "$NAME"
99        do_stop
100        case "$?" in
101          0|1)
102                do_start
103                case "$?" in
104                        0) log_end_msg 0 ;;
105                        1) log_end_msg 1 ;; # Old process is still running
106                        *) log_end_msg 1 ;; # Failed to start
107                esac
108                ;;
109          *)
110                # Failed to stop
111                log_end_msg 1
112                ;;
113        esac
114        ;;
115  status)
116        pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null
117        status=$?
118        if [ $status -eq 0 ]; then
119                log_success_msg "$NAME is running."
120        else
121                log_failure_msg "$NAME is not running."
122        fi
123        exit $status
124        ;;
125  *)
126        echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2
127        exit 3
128        ;;
129esac
130
131:
Note: See TracBrowser for help on using the repository browser.