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

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

Fix debugging mode into collector
Fix n4d checking

  • Property svn:executable set to *
File size: 3.0 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:
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"
22STATUS_FILE=/etc/lliurex-analytics/status
23LOCK_FILE=/var/run/analytics.lock
24
25# Exit if the package is not installed
26[ -x "$DAEMON" ] || exit 0
27
28# Read configuration variable file if it is present
29[ -r /etc/lliurex-analytics/agent.cfg ] || exit 0
30
31# Define LSB log_* functions.
32. /lib/lsb/init-functions
33
34set_acls()
35{
36    if [ -w "${STATUS_FILE}" ]; then
37        # fixed group 10003 for teachers into ldap
38        setfacl -m g:10003:rw ${STATUS_FILE}
39        setfacl -m g:adm:rw ${STATUS_FILE}
40    fi
41}
42remove_locks()
43{
44    if [ -f "${LOCK_FILE}" ]; then
45        log_success_msg "Removing lockfile ${LOCK_FILE}"
46        rm -f ${LOCK_FILE}
47    fi
48}
49#
50# Function that starts the daemon/service
51#
52do_start()
53{
54        # Return
55        #   0 if daemon has been started
56        #   1 if daemon was already running
57        #   2 if daemon could not be started
58        set_acls
59        remove_locks
60        start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" -- \
61                $EXTRAOPTIONS \
62                || return 2
63}
64
65#
66# Function that stops the daemon/service
67#
68do_stop()
69{
70        # Return
71        #   0 if daemon has been stopped
72        #   1 if daemon was already stopped
73        #   2 if daemon could not be stopped
74        #   other if a failure occurred
75        start-stop-daemon --stop --quiet --retry=INT/5/KILL/2 --pidfile "$PIDFILE" --name "$NAME"
76        RETVAL="$?"
77        [ "$RETVAL" = 2 ] && return 2
78        start-stop-daemon --stop --quiet --oknodo --retry=TERM/5/KILL/2 --exec "$DAEMON"
79        [ "$?" = 2 ] && return 2
80        # Many daemons don't delete their pidfiles when they exit.
81        rm -f "$PIDFILE"
82        return "$RETVAL"
83}
84
85#
86# Function that sends a SIGHUP to the daemon/service
87#
88do_reload() {
89        do_stop
90        do_start
91        return 0
92}
93
94case "$1" in
95  start)
96        log_daemon_msg "Starting $DESC" "$NAME"
97        do_start
98        case "$?" in
99                0|1) log_end_msg 0 ;;
100                2) log_end_msg 1 ;;
101        esac
102        ;;
103  stop)
104        log_daemon_msg "Stopping $DESC" "$NAME"
105        do_stop
106        case "$?" in
107                0|1) log_end_msg 0 ;;
108                2) log_end_msg 1 ;;
109        esac
110        ;;
111  reload|force-reload)
112        log_daemon_msg "Reloading $DESC" "$NAME"
113        do_reload
114        log_end_msg $?
115        ;;
116  restart)
117        log_daemon_msg "Restarting $DESC" "$NAME"
118        do_stop
119        case "$?" in
120          0|1)
121                do_start
122                case "$?" in
123                        0) log_end_msg 0 ;;
124                        1) log_end_msg 1 ;; # Old process is still running
125                        *) log_end_msg 1 ;; # Failed to start
126                esac
127                ;;
128          *)
129                # Failed to stop
130                log_end_msg 1
131                ;;
132        esac
133        ;;
134  status)
135        pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null
136        status=$?
137        if [ $status -eq 0 ]; then
138                log_success_msg "$NAME is running."
139        else
140                log_failure_msg "$NAME is not running."
141        fi
142        exit $status
143        ;;
144  *)
145        echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2
146        exit 3
147        ;;
148esac
149
150:
Note: See TracBrowser for help on using the repository browser.