1 | #! /bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Copyright Rainer Wichmann (2005)
|
---|
5 | #
|
---|
6 | # License Information:
|
---|
7 | # This program is free software; you can redistribute it and/or modify
|
---|
8 | # it under the terms of the GNU General Public License as published by
|
---|
9 | # the Free Software Foundation; either version 2 of the License, or
|
---|
10 | # (at your option) any later version.
|
---|
11 | #
|
---|
12 | # This program is distributed in the hope that it will be useful,
|
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | # GNU General Public License for more details.
|
---|
16 | #
|
---|
17 | # You should have received a copy of the GNU General Public License
|
---|
18 | # along with this program; if not, write to the Free Software
|
---|
19 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
20 | #
|
---|
21 |
|
---|
22 | startup=no
|
---|
23 |
|
---|
24 | # arg1: the --enable-nocl=password password (use 'start' for none)
|
---|
25 | # arg2(optional): if 'startup', start the client and exit
|
---|
26 | #
|
---|
27 | #
|
---|
28 | # 'nocl' is used to handle the --enable-nocl=password option. 'start' is a
|
---|
29 | # reserved word, hence cannot be the password.
|
---|
30 | # We are called with one argument, which may be 'start' to indicate that
|
---|
31 | # the --enable-nocl=password option is not used.
|
---|
32 | #
|
---|
33 | if test "x$1" = x
|
---|
34 | then
|
---|
35 | nocl=start
|
---|
36 | else
|
---|
37 | nocl="$1"
|
---|
38 | fi
|
---|
39 |
|
---|
40 | if test "x$2" = x
|
---|
41 | then
|
---|
42 | command="data"
|
---|
43 | else
|
---|
44 | command="$2"
|
---|
45 | fi
|
---|
46 |
|
---|
47 | name=`./samhain-install.sh --print-config name`
|
---|
48 | sbin=`./samhain-install.sh --print-config sbin_dir`
|
---|
49 |
|
---|
50 | # execute and exit for start|stop|restart|reload|status, else fallthrough
|
---|
51 | case $command in
|
---|
52 | start | stop)
|
---|
53 | MONIT=""
|
---|
54 | test -f /usr/local/bin/monit && MONIT="/usr/local/bin/monit"
|
---|
55 | if test x"$MONIT" = x
|
---|
56 | then
|
---|
57 | test -f /usr/bin/monit && MONIT="/usr/bin/monit"
|
---|
58 | if test x"$MONIT" = x
|
---|
59 | then
|
---|
60 | :
|
---|
61 | else
|
---|
62 | zz=`/usr/bin/monit status | grep ${name}`
|
---|
63 | if test x"$zz" = x
|
---|
64 | then
|
---|
65 | :
|
---|
66 | else
|
---|
67 | ${MONIT} "${command}" "${name}"
|
---|
68 | exit 0
|
---|
69 | fi
|
---|
70 | fi
|
---|
71 | fi
|
---|
72 |
|
---|
73 | retval=0
|
---|
74 |
|
---|
75 | if test -f /etc/init.d/${name}
|
---|
76 | then
|
---|
77 | /etc/init.d/${name} ${command}
|
---|
78 | retval=$?
|
---|
79 | elif test -f /etc/rc.d/init.d/${name}
|
---|
80 | then
|
---|
81 | /etc/rc.d/init.d/${name} ${command}
|
---|
82 | retval=$?
|
---|
83 | elif test -f "$sbin/$name"
|
---|
84 | then
|
---|
85 | $sbin/$name ${command}
|
---|
86 | retval=$?
|
---|
87 | else
|
---|
88 | exit 1
|
---|
89 | fi
|
---|
90 | if test x"$command" = xstop
|
---|
91 | then
|
---|
92 | exit 0
|
---|
93 | fi
|
---|
94 | exit $retval
|
---|
95 | ;;
|
---|
96 |
|
---|
97 | reload | restart | status )
|
---|
98 | if test -f /etc/init.d/${name}
|
---|
99 | then
|
---|
100 | /etc/init.d/${name} ${command}
|
---|
101 | elif test -f /etc/rc.d/init.d/${name}
|
---|
102 | then
|
---|
103 | /etc/rc.d/init.d/${name} ${command}
|
---|
104 | elif test -f "$sbin/$name"
|
---|
105 | then
|
---|
106 | $sbin/$name ${command}
|
---|
107 | else
|
---|
108 | exit 1
|
---|
109 | fi
|
---|
110 | exit $?
|
---|
111 | ;;
|
---|
112 |
|
---|
113 | *)
|
---|
114 | ;;
|
---|
115 | esac
|
---|
116 |
|
---|
117 | data=`./samhain-install.sh --print-config data_file`
|
---|
118 | ddir=`./samhain-install.sh --print-config data_dir`
|
---|
119 |
|
---|
120 | remfile=no
|
---|
121 | remdir=no
|
---|
122 |
|
---|
123 | if test -d "$ddir"
|
---|
124 | then
|
---|
125 | test -f "$data" || remfile=yes
|
---|
126 | else
|
---|
127 | ./samhain-install.sh --mkinstalldirs "$ddir"
|
---|
128 | remdir=yes
|
---|
129 | fi
|
---|
130 |
|
---|
131 | if test -f "$sbin/$name"
|
---|
132 | then
|
---|
133 | if test -f "$data"
|
---|
134 | then
|
---|
135 | rm "$data" || exit 1
|
---|
136 | fi
|
---|
137 |
|
---|
138 | if test x"$nocl" = xstart
|
---|
139 | then
|
---|
140 | $sbin/$name -t init -p err
|
---|
141 | else
|
---|
142 | echo '-t init -p err' | $sbin/$name "$nocl"
|
---|
143 | fi
|
---|
144 | else
|
---|
145 | echo "$sbin/$name not found" >&2
|
---|
146 | exit 1
|
---|
147 | fi
|
---|
148 |
|
---|
149 | if test -f "$data"
|
---|
150 | then
|
---|
151 | cp "$data" ./data
|
---|
152 | else
|
---|
153 | echo "$data not found" >&2
|
---|
154 | exit 1
|
---|
155 | fi
|
---|
156 |
|
---|
157 | if test x"$remdir" = xyes
|
---|
158 | then
|
---|
159 | rm -rf "$ddir"
|
---|
160 | elif test x"$remfile" = xyes
|
---|
161 | then
|
---|
162 | rm -f "$data"
|
---|
163 | fi
|
---|
164 |
|
---|
165 | exit 0
|
---|
166 |
|
---|