rewrite of service script

This commit is contained in:
Renè Thümmler 2019-09-07 23:57:23 +02:00
parent f0ad1a91cb
commit 8722786e8e

View File

@ -7,6 +7,9 @@
# KEYWORD: shutdown # KEYWORD: shutdown
# #
# isso_enable="YES" # isso_enable="YES"
# isso_bin="/usr/local/bin/isso"
# isso_config="/usr/local/etc/isso.conf"
# isso_user="www"
# #
. /etc/rc.subr . /etc/rc.subr
@ -18,43 +21,54 @@ desc="isso commenting service"
load_rc_config ${name} load_rc_config ${name}
: ${isso_enable:=NO} : ${isso_enable:=NO}
: ${isso_bin=/usr/local/bin/isso}
: ${isso_config=/usr/local/etc/isso.conf} : ${isso_config=/usr/local/etc/isso.conf}
: ${isso_user=www}
logfile=/var/log/isso.log logfile=/var/log/isso.log
pidfile=/var/run/isso.pid pidfile=/var/run/isso.pid
command=/usr/local/bin/isso command="${isso_bin} -c ${isso_config} run"
start_cmd=isso_start start_cmd=isso_start
status_cmd=isso_status
stop_cmd=isso_stop stop_cmd=isso_stop
procname=/usr/sbin/daemon procname=/usr/sbin/daemon
is_process_running="[ -f $pidfile ] && procstat $(cat $pidfile) >/dev/null 2>&1"
isso_start() isso_start()
{ {
if is_process_running; then if [ -f ${pidfile} ]; then
echo "isso is already running (pid=$(cat $pidfile))" echo "isso is already running (pid=$(cat ${pidfile}))"
return 1 return 1
fi fi
export USER=www export USER=${isso_user}
export HOME=$(echo ~www) export HOME=$(echo ~${isso_user})
touch $logfile touch ${logfile}
chmod 640 $logfile chmod 640 ${logfile}
/usr/sbin/daemon -P $pidfile -u www /usr/local/bin/isso -c ${isso_config} run >>$logfile 2>&1 ${procname} -P ${pidfile} -u ${isso_user} ${command} >>${logfile} 2>&1
if is_process_running; then if [ -f ${pidfile} ]; then
echo "started isso (pid=$(cat $pidfile))" echo "started isso (pid=$(cat ${pidfile}))"
else else
echo "failed to start isso" echo "failed to start isso"
fi fi
} }
isso_status()
{
if [ -f ${pidfile} ]; then
echo "isso is running (pid=$(cat ${pidfile}))"
else
echo "isso is not running"
return 1
fi
}
isso_stop() isso_stop()
{ {
if is_process_running; then if [ -f ${pidfile} ]; then
local pid=$(cat $pidfile) local pid=$(cat $pidfile)
echo "stopping isso (pid=$pid)" echo "stopping isso (pid=$pid)"
kill -- -$pid kill -- -$pid
else else
echo "isso isn't running" echo "isso is not running"
fi fi
} }