2
1
# Common start-stop code for server and master server
3
# tested on Gentoo Linux 2004.4
4
# Author: Manuel Moos <manuel@moosnet.de>
9
3
# determine required su command
10
test "$user" = "$USER" || SU="su $user -c"
4
[ X"${user}" = X"${USER}" ] || SU="su ${user} -c"
12
6
# create directories writable by user
13
test -d $VARDIR || mkdir -p $VARDIR
14
test -d $LOGDIR || mkdir -p $LOGDIR
15
test -d $PIDDIR || mkdir -p $PIDDIR
16
#chmod 755 `dirname $VARDIR` -R
17
#chown -R "$user" $LOGDIR
18
#chown -R "$user" $PIDDIR
19
chown -R "$user" $VARDIR
7
[ -d ${VARDIR} ] || mkdir -p ${VARDIR}
8
[ -d ${LOGDIR} ] || mkdir -p ${LOGDIR}
9
[ -d ${PIDDIR} ] || mkdir -p ${PIDDIR}
10
chown -R "${user}" ${VARDIR}
21
12
# export PIDDIR and VARDIR for service starter script
25
16
# ps command listing all PIDs
29
test -n "$rc_done" || rc_done=" done."
30
test -n "$rc_failed" || rc_failed=" failed."
20
[ -n "${rc_done}" ] || rc_done=" done."
21
[ -n "${rc_failed}" ] || rc_failed=" failed."
32
23
# The echo return value for success (defined in /etc/rc.config).
36
27
if $0 status > /dev/null 2>&1; then
37
echo "@prognamebase@ $TYPE not started, already running."
28
echo "@prognamebase@ ${TYPE} not started, already running."
40
rm -f $MAINPIDFILE $STARTERPIDFILE
41
touch -f $MAINPIDFILE $STARTERPIDFILE
42
echo -n "Starting @prognamebase@ $TYPE..."
43
if test "$user" = "$USER"; then
44
{ nohup $BINFILE $server_args >> $LOGFILE 2>&1 & } > /dev/null 2>&1
45
#$BINFILE $server_args
31
rm -f ${MAINPIDFILE} ${STARTERPIDFILE}
32
touch -f ${MAINPIDFILE} ${STARTERPIDFILE}
33
echo -n "Starting @prognamebase@ ${TYPE}..."
34
if [ X"${user}" = X"${USER}" ]; then
35
{ nohup ${BINFILE} ${server_args} >> ${LOGFILE} 2>&1 & } > /dev/null 2>&1
48
chown "$user" $MAINPIDFILE $STARTERPIDFILE
51
{ nohup $SU "$BINFILE $server_args" >> $LOGFILE 2>&1 & } > /dev/null 2>&1
52
#$SU "$BINFILE $server_args
38
chown "${user}" ${MAINPIDFILE} ${STARTERPIDFILE}
39
{ nohup ${SU} "${BINFILE} ${server_args}" >> ${LOGFILE} 2>&1 & } > /dev/null 2>&1
56
while test $COUNT -gt 0; do
57
test -s $MAINPIDFILE && COUNT=0 || sleep 1
43
while [ ${COUNT} -gt 0 ]; do
44
[ -s ${MAINPIDFILE} ] && COUNT=0 || sleep 1
60
test -s $MAINPIDFILE || return=$rc_failed
62
if test "$niceness_level" != "" && test "$niceness_level" != "0"; then
63
renice $niceness_level -p `cat $MAINPIDFILE` > /dev/null
64
renice $niceness_level -p `cat $STARTERPIDFILE` > /dev/null
47
[ -s ${MAINPIDFILE} ] || return=${rc_failed}
49
if [ X"${niceness_level}" != X"" -a X"${niceness_level}" != X"0" ]; then
50
renice ${niceness_level} -p `cat ${MAINPIDFILE}` > /dev/null
51
renice ${niceness_level} -p `cat ${STARTERPIDFILE}` > /dev/null
68
echo -n "Shutting down @prognamebase@ $TYPE..."
55
echo -n "Shutting down @prognamebase@ ${TYPE}..."
71
test -s $MAINPIDFILE && MAINPID=$( cat $MAINPIDFILE ) || return=$rc_failed
72
test -s $STARTERPIDFILE && STARTERPID=$( cat $STARTERPIDFILE ) || return=$rc_failed
73
test -n "$STARTERPID" && kill -TERM $STARTERPID || return=$rc_failed
74
test -n "$MAINPID" && kill -TERM $MAINPID || return=$rc_failed
58
[ -s ${MAINPIDFILE} ] && MAINPID=$( cat ${MAINPIDFILE} ) || return=${rc_failed}
59
[ -s ${STARTERPIDFILE} ] && STARTERPID=$( cat ${STARTERPIDFILE} ) || return=${rc_failed}
60
[ -n "${STARTERPID}" ] && kill -TERM ${STARTERPID} || return=${rc_failed}
61
[ -n "${MAINPID}" ] && kill -TERM ${MAINPID} || return=${rc_failed}
62
rm -f ${STARTERPIDFILE}
81
$0 stop ; $0 start || return=$rc_failed
68
$0 stop ; sleep 1 ; $0 start || return=${rc_failed}
84
echo -n "Checking for service @prognamebase@ $TYPE: "
71
echo -n "Checking for service @prognamebase@ ${TYPE}: "
87
test -s $STARTERPIDFILE || RESPONSE="Not running"
88
test "$RESPONSE" = "OK" && { test -s $MAINPIDFILE || RESPONSE="Inconsistent. Starter PID logged, but server PID missing"; }
89
test "$RESPONSE" = "OK" && { $PS | grep $(cat $STARTERPIDFILE) >/dev/null || RESPONSE="Inconsistent. PIDs logged, but no service running"; }
90
test "$RESPONSE" = "OK" && { $PS | grep $(cat $MAINPIDFILE) >/dev/null || RESPONSE="Inconsistent. PIDs logged, starter is running, but server is missing."; }
74
[ -s ${STARTERPIDFILE} ] || RESPONSE="Not running"
75
[ X"$RESPONSE" = X"OK" ] && { [ -s ${MAINPIDFILE} ] || RESPONSE="Inconsistent. Starter PID logged, but server PID missing"; }
76
[ X"$RESPONSE" = X"OK" ] && { ${PS} | grep $(cat ${STARTERPIDFILE}) >/dev/null || RESPONSE="Inconsistent. PIDs logged, but no service running"; }
77
[ X"$RESPONSE" = X"OK" ] && { ${PS} | grep $(cat ${MAINPIDFILE}) >/dev/null || RESPONSE="Inconsistent. PIDs logged, starter is running, but server is missing."; }
93
test "$RESPONSE" = "OK" || exit 1
80
[ X"${RESPONSE}" = X"OK" ] || exit 1
97
echo "Usage: $0 {start|stop|status|restart}"
87
echo "Usage: $0 {start|stop|status|restart|log}"
101
91
# Inform the caller not only verbosely and set an exit status.
102
test "$return" = "$rc_done" || exit 1
92
test "${return}" = "${rc_done}" || exit 1