File: auth2db.init.d

package info (click to toggle)
auth2db 0.2.5-2%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,508 kB
  • ctags: 1,090
  • sloc: python: 2,280; php: 2,161; sh: 174; sql: 157; makefile: 81
file content (132 lines) | stat: -rw-r--r-- 3,721 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#! /bin/bash
#
# This initscript was created by Ulises Vitulli <uvitulli@fi.uba.ar> for Auth2DB
#
# Start/stop the auth2db daemon
### BEGIN INIT INFO
# Provides:          auth2db
# Required-Start:    $syslog $remote_fs $time
# Required-Stop:     $syslog $remote_fs $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Log parser and database loader
# Description:       This daemon consists in a generic log parser and a database
#                    loader, making available to read either with a web frontend 
#		     or classic shell console UI.
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/auth2db-daemon
NAME=auth2db
DESC="log examiner and database loader"
PIDFILE=/var/run/$NAME/$NAME.pid
USER=auth2db
GROUP=adm

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

# Include auth2db defaults if available
if [ -f /etc/default/auth2db ] ; then
        . /etc/default/auth2db
	if [ "$FREQUENCY" = "" ]; then
		log_failure_msg "FATAL ERROR: Daemon configuration is broken. 'FREQUENCY' parameter must have set a value."
		log_end_msg 1
		exit 1
	fi
	if [ "$FREQUENCY" -eq "0" ]; then
		log_failure_msg "FATAL ERROR: Frequency MUST be a value higher than 0. NOT STARTING."
		log_failure_msg "Check /usr/share/doc/auth2db/README.Debian for more information."
		log_end_msg 1
		exit 1
	elif [ "$FREQUENCY" -gt "0" ] && [ "$FREQUENCY" -lt "5" ] ; then
		if [ "$IWouldLoveToRosteMyDB" = "" ]; then
			log_warning_msg "It's recommended setting a frequency value higher than 5 seconds."
			log_warning_msg "Check /usr/share/doc/auth2db/README.Debian for more information."
		fi
	fi
else                            
        log_failure_msg "FATAL ERROR: auth2db daemon configuration file MISSING!"
	log_failure_msg "Check /usr/share/doc/auth2db/README.Debian"
        log_end_msg 1
	exit 1                  
fi

check_process() {
	# Is process really running???
	PID=$(cat "$PIDFILE")
	if ps --pid "$PID" | grep "$NAME" >/dev/null; then
		return 0
	else 
		return 1
	fi
}

case "$1" in
    start)
	log_daemon_msg "Starting $DESC daemon" "$NAME"
	if [ -s "$PIDFILE" ] && check_process ; then
	      log_action_msg "Already running."
	      log_end_msg 0
      	else 
		if [ ! -d "/var/run/$NAME" ]; then 
			mkdir -p /var/run/$NAME
			chown $USER:root /var/run/auth2db
		fi
		if start-stop-daemon --test --start --oknodo --user "$USER" >/dev/null \
				--pidfile "$PIDFILE" --exec $DAEMON $1; then
			su -p -s /bin/sh "$USER" -c "$DAEMON $1 3>/dev/null"
			sleep 1
		fi
	
		if [ ! -s "$PIDFILE" ]; then
			log_failure_msg "Oops, something went wront. CHECK SYSLOG!"
			log_end_msg $?
		fi
		log_end_msg $?
	fi
	;;
    stop)
	# Performing a full check of the status of the process
    	if [ -e "$PIDFILE" ]; then
		if [ -s "$PIDFILE" ]; then
			if check_process; then
				log_daemon_msg "Stopping $DESC daemon" "$NAME"
				$DAEMON $1
				log_end_msg $?
			else
				log_failure_msg "Pidfile exists but there is no process asossiated. (System halted prematurely?)"
				log_end_msg 1
			fi
		else
			log_begin_msg "Something went wrong. Pidfile exists but it is not assosiated with any process. Deleting..."
			rm "$PIDFILE"
			log_end_msg $?
		fi
	else
		log_progress_msg "$NAME is already stopped. Nothing to be done"
		log_end_msg 0
	fi		
	;;
    force-reload)
	$0 restart
	;;
    restart)
	$0 stop
	$0 start
	;;
    status)
    	if [ -s /var/run/$NAME/$NAME.pid ]; then
		log_action_msg "$NAME is RUNNING under PID $(cat /var/run/$NAME/$NAME.pid)." && exit 0
	else
		log_action_msg "$NAME is STOPPED!" && exit 1
	fi
	;;		
    *)
	log_success_msg "Usage: /etc/init.d/$NAME {start|stop|status|force-reload|restart}"
	exit 1
	;;
esac

exit 0