Imported Upstream version 2.5.1
[ossec-hids.git] / src / init / ossec-hids-gentoo.init
1 #!/sbin/runscript
2 # Gentoo init script
3 # by gentuxx <gentuxx@gmail.com>
4
5
6 opts="${opts} status configtest"
7
8 # Finding where ossec is installed
9 . /etc/ossec-init.conf
10 if [ "X${DIRECTORY}" = "X" ]; then
11     DIRECTORY="/var/ossec"
12 fi
13         
14 OSSEC_CONTROL="${DIRECTORY}/bin/ossec-control"
15
16 depend() {
17         need net
18         use logger
19 }
20
21 configtest() {
22         ebegin "Checking OSSEC Configuration"
23         checkconfig
24         eend $?
25 }
26
27 checkconfig() {
28         
29         CONFIGFILE="${CONFIGFILE:-${DIRECTORY}/etc/ossec.conf}"
30         if [ ! -r "${CONFIGFILE}" ]; then
31                 eerror "Unable to read configuration file: ${CONFIGFILE}"
32                 return 1
33         fi
34
35         # Maybe put some kind of config file syntax checking in here?  XML is a little different
36         # so maybe not. 
37         return $ret
38 }
39
40 start() {
41         checkconfig || return 1
42         ebegin "Starting ossec-hids"
43         ${OSSEC_CONTROL} start > /dev/null 2>&1
44         eend $?
45 }
46
47 stop() {
48         checkconfig || return 1
49         ebegin "Stopping ossec-hids"
50         ${OSSEC_CONTROL} stop > /dev/null 2>&1
51         eend $?
52 }
53
54 restart() {
55         if ! service_started "${myservice}" ; then
56                 eerror "OSSEC is not running! Please start it before trying to reload it."
57         else
58                 checkconfig || return 1
59                 ebegin "Reloading ossec"
60                 svc_stop ${OSSEC_CONTROL}
61                 svc_start ${OSSEC_CONTROL}
62                 eend $?
63         fi
64 }
65
66 status() {
67         checkconfig || return 1
68         ${OSSEC_CONTROL} status
69 }