1 | #! /bin/sh
|
---|
2 |
|
---|
3 | startup=no
|
---|
4 |
|
---|
5 | # arg1: the --enable-nocl=password password (use 'start' for none)
|
---|
6 | # arg2(optional): if 'startup', start the client and exit
|
---|
7 | #
|
---|
8 | #
|
---|
9 | # 'nocl' is used to handle the --enable-nocl=password option. 'start' is a
|
---|
10 | # reserved word, hence cannot be the password.
|
---|
11 | # We are called with one argument, which may be 'start' to indicate that
|
---|
12 | # the --enable-nocl=password option is not used.
|
---|
13 | #
|
---|
14 | if test "x$1" = x
|
---|
15 | then
|
---|
16 | nocl=start
|
---|
17 | else
|
---|
18 | nocl="$1"
|
---|
19 | fi
|
---|
20 |
|
---|
21 | if test "x$2" = x
|
---|
22 | then
|
---|
23 | command="data"
|
---|
24 | else
|
---|
25 | command="$2"
|
---|
26 | fi
|
---|
27 |
|
---|
28 | name=`./samhain-install.sh --print-config name`
|
---|
29 | sbin=`./samhain-install.sh --print-config sbin_dir`
|
---|
30 |
|
---|
31 | # execute and exit for start|stop|restart|reload|status, else fallthrough
|
---|
32 | case $command in
|
---|
33 | start | stop)
|
---|
34 | MONIT=""
|
---|
35 | test -f /usr/local/bin/monit && MONIT="/usr/local/bin/monit"
|
---|
36 | if test x"$MONIT" = x
|
---|
37 | then
|
---|
38 | test -f /usr/bin/monit && MONIT="/usr/bin/monit"
|
---|
39 | if test x"$MONIT" = x
|
---|
40 | then
|
---|
41 | :
|
---|
42 | else
|
---|
43 | zz=`/usr/bin/monit status | grep ${name}`
|
---|
44 | if test x"$zz" = x
|
---|
45 | then
|
---|
46 | :
|
---|
47 | else
|
---|
48 | ${MONIT} "${command}" "${name}"
|
---|
49 | exit 0
|
---|
50 | fi
|
---|
51 | fi
|
---|
52 | fi
|
---|
53 |
|
---|
54 | retval=0
|
---|
55 |
|
---|
56 | if test -f /etc/init.d/${name}
|
---|
57 | then
|
---|
58 | /etc/init.d/${name} ${command}
|
---|
59 | retval=$?
|
---|
60 | elif test -f /etc/rc.d/init.d/${name}
|
---|
61 | then
|
---|
62 | /etc/rc.d/init.d/${name} ${command}
|
---|
63 | retval=$?
|
---|
64 | elif test -f "$sbin/$name"
|
---|
65 | then
|
---|
66 | $sbin/$name ${command}
|
---|
67 | retval=$?
|
---|
68 | else
|
---|
69 | exit 1
|
---|
70 | fi
|
---|
71 | if test x"$command" = xstop
|
---|
72 | then
|
---|
73 | exit 0
|
---|
74 | fi
|
---|
75 | exit $retval
|
---|
76 | ;;
|
---|
77 |
|
---|
78 | reload | restart | status )
|
---|
79 | if test -f /etc/init.d/${name}
|
---|
80 | then
|
---|
81 | /etc/init.d/${name} ${command}
|
---|
82 | elif test -f /etc/rc.d/init.d/${name}
|
---|
83 | then
|
---|
84 | /etc/rc.d/init.d/${name} ${command}
|
---|
85 | elif test -f "$sbin/$name"
|
---|
86 | then
|
---|
87 | $sbin/$name ${command}
|
---|
88 | else
|
---|
89 | exit 1
|
---|
90 | fi
|
---|
91 | exit $?
|
---|
92 | ;;
|
---|
93 |
|
---|
94 | *)
|
---|
95 | ;;
|
---|
96 | esac
|
---|
97 |
|
---|
98 | data=`./samhain-install.sh --print-config data_file`
|
---|
99 | ddir=`./samhain-install.sh --print-config data_dir`
|
---|
100 |
|
---|
101 | remfile=no
|
---|
102 | remdir=no
|
---|
103 |
|
---|
104 | if test -d "$ddir"
|
---|
105 | then
|
---|
106 | test -f "$data" || remfile=yes
|
---|
107 | else
|
---|
108 | ./samhain-install.sh --mkinstalldirs "$ddir"
|
---|
109 | remdir=yes
|
---|
110 | fi
|
---|
111 |
|
---|
112 | if test -f "$sbin/$name"
|
---|
113 | then
|
---|
114 | if test -f "$data"
|
---|
115 | then
|
---|
116 | rm "$data" || exit 1
|
---|
117 | fi
|
---|
118 |
|
---|
119 | if test x"$nocl" = xstart
|
---|
120 | then
|
---|
121 | $sbin/$name -t init -p err
|
---|
122 | else
|
---|
123 | echo '-t init -p err' | $sbin/$name "$nocl"
|
---|
124 | fi
|
---|
125 | else
|
---|
126 | echo "$sbin/$name not found" >&2
|
---|
127 | exit 1
|
---|
128 | fi
|
---|
129 |
|
---|
130 | if test -f "$data"
|
---|
131 | then
|
---|
132 | cp "$data" ./data
|
---|
133 | else
|
---|
134 | echo "$data not found" >&2
|
---|
135 | exit 1
|
---|
136 | fi
|
---|
137 |
|
---|
138 | if test x"$remdir" = xyes
|
---|
139 | then
|
---|
140 | rm -rf "$ddir"
|
---|
141 | elif test x"$remfile" = xyes
|
---|
142 | then
|
---|
143 | rm -f "$data"
|
---|
144 | fi
|
---|
145 |
|
---|
146 | exit 0
|
---|
147 |
|
---|