source: trunk/dsys/initscript@ 504

Last change on this file since 504 was 27, checked in by rainer, 19 years ago

Support for server-to-server relay and more user policies

File size: 3.3 KB
Line 
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
22startup=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#
33if test "x$1" = x
34then
35 nocl=start
36else
37 nocl="$1"
38fi
39
40if test "x$2" = x
41then
42 command="data"
43else
44 command="$2"
45fi
46
47name=`./samhain-install.sh --print-config name`
48sbin=`./samhain-install.sh --print-config sbin_dir`
49
50# execute and exit for start|stop|restart|reload|status, else fallthrough
51case $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 ;;
115esac
116
117data=`./samhain-install.sh --print-config data_file`
118ddir=`./samhain-install.sh --print-config data_dir`
119
120remfile=no
121remdir=no
122
123if test -d "$ddir"
124then
125 test -f "$data" || remfile=yes
126else
127 ./samhain-install.sh --mkinstalldirs "$ddir"
128 remdir=yes
129fi
130
131if test -f "$sbin/$name"
132then
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
144else
145 echo "$sbin/$name not found" >&2
146 exit 1
147fi
148
149if test -f "$data"
150then
151 cp "$data" ./data
152else
153 echo "$data not found" >&2
154 exit 1
155fi
156
157if test x"$remdir" = xyes
158then
159 rm -rf "$ddir"
160elif test x"$remfile" = xyes
161then
162 rm -f "$data"
163fi
164
165exit 0
166
Note: See TracBrowser for help on using the repository browser.