File: initscript

package info (click to toggle)
samhain 4.1.4-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,720 kB
  • sloc: ansic: 84,043; sh: 15,325; asm: 5,756; makefile: 1,614; perl: 1,231
file content (166 lines) | stat: -rw-r--r-- 3,357 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#! /bin/sh

#
# Copyright Rainer Wichmann (2005)
#
# License Information:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

startup=no

# arg1: the --enable-nocl=password password (use 'start' for none)
# arg2(optional): if 'startup', start the client and exit
#
#
# 'nocl' is used to handle the --enable-nocl=password option. 'start' is a
# reserved word, hence cannot be the password.
# We are called with one argument, which may be 'start' to indicate that
# the --enable-nocl=password option is not used.
#
if test "x$1" = x
then
    nocl=start
else
    nocl="$1"
fi

if test "x$2" = x
then
    command="data"
else
    command="$2"
fi

name=`./samhain-install.sh --print-config name`
sbin=`./samhain-install.sh --print-config sbin_dir`

# execute and exit for start|stop|restart|reload|status, else fallthrough
case $command in
    start | stop)
    MONIT=""
    test -f /usr/local/bin/monit && MONIT="/usr/local/bin/monit"
    if test x"$MONIT" = x
    then
	test -f /usr/bin/monit && MONIT="/usr/bin/monit"
        if test x"$MONIT" = x
        then
	    :
	else
	    zz=`/usr/bin/monit status | grep ${name}`
	    if test x"$zz" = x
	    then
		:
	    else
	        ${MONIT} "${command}" "${name}"
		exit 0
	    fi
	fi
    fi

    retval=0

    if test -f /etc/init.d/${name}
    then
        /etc/init.d/${name} ${command}
	retval=$?
    elif test -f /etc/rc.d/init.d/${name}
    then
        /etc/rc.d/init.d/${name} ${command}
	retval=$?
    elif test -f "$sbin/$name"
    then
    	$sbin/$name ${command}
	retval=$?
    else
        exit 1
    fi
    if test x"$command" = xstop
    then
        exit 0
    fi
    exit $retval
    ;;

    reload | restart | status )
    if test -f /etc/init.d/${name}
    then
        /etc/init.d/${name} ${command}
    elif test -f /etc/rc.d/init.d/${name}
    then
        /etc/rc.d/init.d/${name} ${command}
    elif test -f "$sbin/$name"
    then
    	$sbin/$name ${command}
    else
        exit 1
    fi
    exit $?
    ;;

    *)
    ;;
esac

data=`./samhain-install.sh --print-config data_file`
ddir=`./samhain-install.sh --print-config data_dir`

remfile=no
remdir=no

if test -d "$ddir"
then
    test -f "$data" || remfile=yes
else
    ./samhain-install.sh --mkinstalldirs "$ddir"
    remdir=yes
fi

if test -f "$sbin/$name"
then
	if test -f "$data"
	then
	    rm "$data" || exit 1
        fi

	if test x"$nocl" = xstart
	then
		$sbin/$name -t init -p err
	else
		echo '-t init -p err' | $sbin/$name "$nocl"
	fi
else
	echo "$sbin/$name not found" >&2
	exit 1
fi

if test -f "$data"
then
	cp "$data" ./data
else
	echo "$data not found" >&2
	exit 1
fi

if test x"$remdir" = xyes
then
    rm -rf "$ddir"
elif test x"$remfile" = xyes
then
    rm -f "$data"
fi

exit 0