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

Last change on this file was 6932, checked in by mabarracus, 19 months ago

Fix writing pid file

  • 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
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=TERM/5/KILL/2 --pidfile "$PIDFILE"
76        RETVAL=$?
77        # Many daemons don't delete their pidfiles when they exit.
78        rm -f "$PIDFILE"
79        return $RETVAL
80}
81
82#
83# Function that sends a SIGHUP to the daemon/service
84#
85do_reload() {
86        do_stop
87        do_start
88        return 0
89}
90
91case "$1" in
92  start)
93        log_daemon_msg "Starting $DESC" "$NAME"
94        do_start
95        case "$?" in
96                0|1) log_end_msg 0 ;;
97                2) log_end_msg 1 ;;
98        esac
99        ;;
100  stop)
101        log_daemon_msg "Stopping $DESC" "$NAME"
102        do_stop
103        case "$?" in
104                0|1) log_end_msg 0 ;;
105                2) log_end_msg 1 ;;
106        esac
107        ;;
108  reload|force-reload)
109        log_daemon_msg "Reloading $DESC" "$NAME"
110        do_reload
111        log_end_msg $?
112        ;;
113  restart)
114        log_daemon_msg "Restarting $DESC" "$NAME"
115        do_stop
116        case "$?" in
117          0|1)
118                do_start
119                case "$?" in
120                        0) log_end_msg 0 ;;
121                        1) log_end_msg 1 ;; # Old process is still running
122                        *) log_end_msg 1 ;; # Failed to start
123                esac
124                ;;
125          *)
126                # Failed to stop
127                log_end_msg 1
128                ;;
129        esac
130        ;;
131  status)
132        pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null
133        status=$?
134        if [ $status -eq 0 ]; then
135                log_success_msg "$NAME is running."
136        else
137                log_failure_msg "$NAME is not running."
138        fi
139        exit $status
140        ;;
141  *)
142        echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2
143        exit 3
144        ;;
145esac
146
147:
Note: See TracBrowser for help on using the repository browser.