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

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

Add debug verbosity
Fixes confirmator logic
Fixes acl's

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