~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/samhain

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
3
 
# Init.d file for Samhain, based on the example init.d file written by
4
 
# Miquel van Smoorenburg and modified for Debian GNU/Linux by Ian Murdock
5
 
#
6
 
### BEGIN INIT INFO
7
 
# Provides:          samhain
8
 
# Required-Start:    $remote_fs $syslog
9
 
# Required-Stop:     $remote_fs $syslog
10
 
# Default-Start:     2 3 4 5
11
 
# Default-Stop:      0 1 6
12
 
### END INIT INFO
13
 
#
14
 
 
15
 
prefix="/usr"
16
 
exec_prefix="${prefix}"
17
 
 
18
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
19
 
DAEMON=${exec_prefix}/sbin/samhain
20
 
NAME=samhain
21
 
DESC="file integrity checker"
22
 
PIDFILE=/var/run/${NAME}/${NAME}.pid
23
 
 
24
 
test -x $DAEMON || exit 0
25
 
 
26
 
. /lib/lsb/init-functions
27
 
 
28
 
set -e
29
 
 
30
 
# Check if a daemon is running
31
 
running()
32
 
{
33
 
# Check with pidfile first, if available
34
 
    if [ -r "$PIDFILE" ] ; then
35
 
            pid=`cat $PIDFILE`
36
 
# No pid, probably no daemon present
37
 
            if [ -n "$pid" ] ; then
38
 
                    pidofproc -p $PIDFILE $DAEMON
39
 
                    return $?
40
 
            fi
41
 
    fi
42
 
# Try to find the daemon by name
43
 
    pidof $DAEMON >/dev/null 
44
 
    return $?
45
 
}
46
 
 
47
 
# Initialize 
48
 
init_db()
49
 
{
50
 
# Initialize the database only if does not exist yet, abort if
51
 
# it cannot be created
52
 
     [  -f /var/state/samhain/samhain_file ] && return
53
 
     log_progress_msg "Creating integrity database (this can take some minutes)."
54
 
     samhain -t init >/var/log/samhain/samhain-init.log 2>&1
55
 
     if [  ! -f /var/state/samhain/samhain_file ] ; then
56
 
        log_failure_msg "Database could not be created. Review /var/log/samhain/samhain-init.log"
57
 
        log_end_msg 1
58
 
        exit 1
59
 
    fi
60
 
    log_progress_msg "Database created."
61
 
}
62
 
 
63
 
 
64
 
 
65
 
case "$1" in
66
 
  start)
67
 
        [ ! -e /var/run/${NAME} ] && mkdir -p /var/run/${NAME}
68
 
        log_begin_msg "Starting $DESC: $NAME"
69
 
        init_db
70
 
        start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
71
 
        log_end_msg $?
72
 
        ;;
73
 
  stop)
74
 
        log_begin_msg "Stopping $DESC: $NAME"
75
 
        start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE  --name  $NAME 
76
 
        log_end_msg $?
77
 
        ;;
78
 
  reload)
79
 
        log_begin_msg "Reloading $DESC configuration files: $NAME"
80
 
        if running ; then
81
 
                start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON
82
 
                log_end_msg $?
83
 
        else
84
 
                log_daemon_msg " ERROR: $DAEMON is not running."
85
 
                log_end_msg 1
86
 
        fi
87
 
 
88
 
        ;;
89
 
  restart|force-reload)
90
 
        log_begin_msg "Restarting $DESC: $NAME"
91
 
        if running; then
92
 
                start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE  --name  $NAME 
93
 
                for i in 1 2 3 ; do
94
 
                    if ! running; then break ; fi
95
 
                    sleep 1
96
 
                done
97
 
        fi
98
 
        if  ! running  ; then
99
 
            start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
100
 
            log_end_msg $?
101
 
        else
102
 
            log_daemon_msg " ERROR: $DAEMON did not die in the expected time, will not restart/force-reload"
103
 
            log_end_msg 1
104
 
        fi
105
 
        ;;
106
 
   status)
107
 
        if [ -e $PIDFILE ] ; then
108
 
                status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
109
 
        else
110
 
                status_of_proc $DAEMON $NAME && exit 0 || exit $?
111
 
        fi
112
 
        ;;
113
 
  *)
114
 
        N=/etc/init.d/${0##*/}
115
 
        echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
116
 
        exit 1
117
 
        ;;
118
 
esac
119
 
 
120
 
exit 0