1#!/bin/bash
2# chkconfig: 2345 99 10
3# description: File Integrity Checking Daemon
4#
5# processname: samhain
6# config  : /etc/samhainrc
7# logfile : /var/log/samhain_log
8# database: /var/lib/samhain/samhain_file
9#
10
11NAME=samhain
12DAEMON=/usr/sbin/samhain
13RETVAL=0
14PIDFILE=/var/run/samhain.pid
15
16. /etc/default/rcS
17
18. /etc/default/samhain-client
19
20if [ "x$SAMHAIN_CLIENT_START" != "xyes" ]; then
21	echo "${0}: client disabled in /etc/default/samhain-client"
22	exit 0
23fi
24
25if [ -x $DAEMON ]; then
26	:
27else
28	echo "${0}: executable ${DAEMON} not found"
29	exit 1
30fi
31
32if [ ! -e /var/lib/samhain/samhain_file ]; then
33	echo "${0}: /var/lib/samhain/samhain_file does not exist.  You must"
34	echo "  run 'samhain -t init' before samhian-client can start."
35	exit 1
36fi
37
38samhain_done()
39{
40	if [ $RETVAL -eq 0 ]; then
41		echo "."
42	else
43		echo " failed."
44	fi
45}
46
47log_stat_msg () {
48case "$1" in
49	0)
50	echo "Service $NAME: Running";
51	;;
52	1)
53	echo "Service $NAME: Stopped and /var/run pid file exists";
54	;;
55	3)
56	echo "Service $NAME: Stopped";
57	;;
58	*)
59	echo "Service $NAME: Status unknown";
60	;;
61esac
62}
63
64case "$1" in
65  start)
66	#
67	# Remove a stale PID file, if found
68	#
69	if test -f ${PIDFILE}; then
70	    /bin/rm -f ${PIDFILE}
71	fi
72	#
73        echo -n "Starting ${NAME}"
74        start-stop-daemon --start --quiet --exec $DAEMON
75	RETVAL=$?
76	samhain_done
77	;;
78
79  stop)
80        echo -n "Stopping $NAME"
81        start-stop-daemon --stop --quiet --exec $DAEMON
82	RETVAL=$?
83
84	#
85	# Remove a stale PID file, if found
86	#
87	if test -f ${PIDFILE}; then
88	    /bin/rm -f ${PIDFILE}
89	fi
90        if test -S /var/run/${NAME}.sock; then
91            /bin/rm -f /var/run/${NAME}.sock
92        fi
93	samhain_done
94	;;
95
96  restart)
97	$0 stop
98	sleep 3
99	$0 start
100	RETVAL=$?
101	;;
102
103  reload|force-reload)
104        echo -n "Reloading $NAME configuration files"
105        start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
106	RETVAL=$?
107	samhain_done
108	;;
109
110  status)
111	$DAEMON status
112	RETVAL=$?
113	log_stat_msg ${RETVAL}
114	;;
115
116  *)
117	echo "$0 usage: {start|stop|status|restart|reload}"
118	exit 1
119	;;
120esac
121
122exit $RETVAL
123