~ubuntu-branches/ubuntu/oneiric/openvas-server/oneiric

« back to all changes in this revision

Viewing changes to packaging/debian/.svn/text-base/openvas-server.init.svn-base

  • Committer: Bazaar Package Importer
  • Author(s): Javier Fernandez-Sanguino Pen~a
  • Date: 2010-10-06 02:10:52 UTC
  • Revision ID: james.westby@ubuntu.com-20101006021052-tqhvq3ckac0sejge
Tags: 2.0.3-4
* Update for PO-debconf translation updates:
  - Updated Brazilian Portuguese Translation, provided by Eder L. Marques
    (Closes: #581744)
  - Updated Italian translation, provided by Vincenzo Campanella (Closes:
    #597312)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -e
 
2
#
 
3
# /etc/init.d/openvasd
 
4
#
 
5
# Originally written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
 
6
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
 
7
# Modified for nessusd by Luca Andreucci <andrew@andrew.org>
 
8
# Further changes by Javier Fernandez-Sanguino <jfs@debian.org> for the 
 
9
# Debian GNU/Linux distribution
 
10
# Even more changes for Debian GNU/Linux openvas-server package by
 
11
# Tim Brown <timb@nth-dimension.org.uk>
 
12
#
 
13
### BEGIN INIT INFO
 
14
# Provides:          openvas-server
 
15
# Required-Start:    $remote_fs
 
16
# Required-Stop:     $remote_fs
 
17
# Should-Start:      
 
18
# Should-Stop:       
 
19
# Default-Start:     
 
20
# Default-Stop:      0 6
 
21
# Short-Description: Start and stop the OpenVAS daemon
 
22
# Description:       Controls the main OpenVAS daemon "openvasd".
 
23
### END INIT INFO
 
24
 
 
25
# daemon options (-D implied, not needed)
 
26
DAEMONOPTS="-q"
 
27
# time to wait for daemons death, in seconds
 
28
# don't set it too low or you might not let openvasd die gracefully
 
29
DODTIME=5
 
30
[ -r /etc/default/openvas-server ] && . /etc/default/openvas-server
 
31
 
 
32
DAEMON=/usr/sbin/openvasd
 
33
PIDFILE=/var/run/openvasd.pid
 
34
NAME=openvasd
 
35
LABEL="OpenVAS daemon"
 
36
 
 
37
test -x $DAEMON || exit 0
 
38
 
 
39
 
 
40
running()
 
41
{
 
42
    # No pidfile, probably no daemon present
 
43
    #
 
44
    [ ! -f "$PIDFILE" ] && return 1
 
45
    pid=`cat $PIDFILE`
 
46
 
 
47
    # No pid, probably no daemon present
 
48
    [ -z "$pid" ] && return 1
 
49
 
 
50
    [ ! -d /proc/$pid ] &&  return 1
 
51
    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
 
52
    # No openvasd?
 
53
    [ "$cmd" != "$NAME" ] &&  return 1
 
54
 
 
55
    return 0
 
56
}
 
57
 
 
58
warn_cert_file() {
 
59
        echo -n "WARN: The (expected) certificate file $1 is not available." >&2
 
60
        echo -n "The OpenVAS daemon might not start up." >&2
 
61
}
 
62
 
 
63
check_certs() {
 
64
        if [ -z "`grep ^ca_file /etc/openvas/openvasd.conf`" ] ; then
 
65
                echo -n "WARN: The openvasd configuration file does not contain certificate settings. Have you run openvas-mkcert? (openvasd might not start)" >&2
 
66
        fi
 
67
        CERTDIR=/var/lib/openvas/CA/
 
68
        PRIVCERTDIR=/var/lib/openvas/private/CA/
 
69
        for cert in cacert.pem servercert.pem; do
 
70
                [ ! -r "$CERTDIR/$cert" ] && warn_cert_file "$CERTDIR/$cert"
 
71
        done
 
72
        for cert in cakey.pem serverkey.pem; do
 
73
                [ ! -r "$PRIVCERTDIR/$cert" ] && warn_cert_file "$CERTDIR/$cert"
 
74
        done
 
75
}
 
76
 
 
77
openvas_start() {
 
78
        if [ ! -r /etc/openvas/openvasd.conf ] ; then
 
79
                echo -n "ERROR: Cannot read openvas configuration file, are you root?" >&2
 
80
                return 1
 
81
        fi
 
82
        check_certs
 
83
        start-stop-daemon --start --exec $DAEMON -- $DAEMONOPTS -D 2>&1 >/dev/null
 
84
        errcode=$?
 
85
# If we don't sleep then running() might not see the pidfile
 
86
        sleep $DODTIME
 
87
        return $errcode
 
88
}
 
89
 
 
90
force_stop() {
 
91
        [ ! -e "$PIDFILE" ] && return
 
92
        if running ; then
 
93
                kill -15 $pid
 
94
        # Is it really dead?
 
95
                sleep "$DODTIME"s
 
96
                if running ; then
 
97
                        kill -9 $pid
 
98
                        sleep "$DODTIME"s
 
99
                        if running ; then
 
100
                                echo "Cannot kill $LABEL (pid=$pid)!"
 
101
                                exit 1
 
102
                        fi
 
103
                fi
 
104
        fi
 
105
        rm -f $PIDFILE
 
106
}
 
107
 
 
108
case "$1" in
 
109
  start)
 
110
    echo -n "Starting $LABEL: "
 
111
    if openvas_start && running ;  then
 
112
            echo "openvasd."
 
113
    else
 
114
            echo "ERROR."
 
115
            exit 1
 
116
    fi
 
117
    ;;
 
118
  stop)
 
119
    echo -n "Stopping $LABEL: "
 
120
    if running ; then
 
121
        start-stop-daemon --stop --pidfile $PIDFILE --quiet --oknodo --exec $DAEMON
 
122
        sleep "$DODTIME"s
 
123
    fi
 
124
    if running; then
 
125
        force_stop
 
126
    fi
 
127
    echo "openvasd."
 
128
      ;;
 
129
  restart)
 
130
    echo -n "Restarting $LABEL: "
 
131
    if running; then
 
132
        start-stop-daemon --stop --pidfile $PIDFILE --quiet --oknodo --exec $DAEMON
 
133
        sleep "$DODTIME"s
 
134
    fi
 
135
    if running; then
 
136
        force_stop
 
137
    fi
 
138
    if openvas_start && running ;  then
 
139
            echo "openvasd."
 
140
    else
 
141
            echo "ERROR."
 
142
            exit 1
 
143
    fi
 
144
    ;;
 
145
  reload|force-reload)
 
146
    echo  -n "Reloading $LABEL configuration files: "
 
147
    start-stop-daemon --stop --pidfile $PIDFILE --signal 1 --exec $DAEMON
 
148
    sleep "$DODTIME"s
 
149
    if running ;  then
 
150
            echo "done."
 
151
    else
 
152
            echo "ERROR."
 
153
            exit 1
 
154
    fi
 
155
    ;;
 
156
  status)
 
157
    echo -n "$LABEL is "
 
158
    if running ;  then
 
159
            echo "running"
 
160
    else
 
161
            echo " not running."
 
162
            exit 1
 
163
    fi
 
164
    ;;
 
165
  *)
 
166
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload|status}"
 
167
    exit 1
 
168
    ;;
 
169
esac
 
170
 
 
171
exit 0