2007-11-13 04:50:41 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2008-12-31 05:26:37 +01:00
|
|
|
DIR=${DIR:-$(dirname $0)}
|
|
|
|
XWRELAY=${DIR}/xwrelay
|
|
|
|
PIDFILE=${DIR}/xwrelay.pid
|
|
|
|
CONFFILE=${DIR}/xwrelay.conf
|
|
|
|
IDFILE=${DIR}/nextid.txt
|
2009-07-31 14:58:47 +02:00
|
|
|
CSSFILE=${DIR}/xwrelay.css
|
|
|
|
|
2009-07-30 14:46:40 +02:00
|
|
|
LOGFILE=/tmp/xwrelay_log.txt
|
|
|
|
#LOGFILE=/dev/null
|
|
|
|
|
|
|
|
date > $LOGFILE
|
2007-11-13 04:50:41 +01:00
|
|
|
|
2008-12-31 05:26:37 +01:00
|
|
|
do_start() {
|
|
|
|
if [ -f $PIDFILE ] && [ -f /proc/$(cat $PIDFILE)/exe ]; then
|
2009-07-30 14:46:40 +02:00
|
|
|
echo "already running: pid=$(cat $PIDFILE)" | tee -a $LOGFILE
|
2008-12-31 05:26:37 +01:00
|
|
|
elif pidof xwrelay >/dev/null; then
|
2009-07-30 14:46:40 +02:00
|
|
|
echo "already running: pid=$(pidof xwrelay)" | tee -a $LOGFILE
|
2008-12-31 05:26:37 +01:00
|
|
|
else
|
2009-07-30 14:46:40 +02:00
|
|
|
echo "starting..." | tee -a $LOGFILE
|
2009-07-31 14:58:47 +02:00
|
|
|
echo "running $XWRELAY $@ -f $CONFFILE -s $CSSFILE" | tee -a $LOGFILE
|
|
|
|
$XWRELAY $@ -f $CONFFILE -i $IDFILE -s $CSSFILE &
|
2008-12-31 05:26:37 +01:00
|
|
|
NEWPID=$!
|
|
|
|
echo $NEWPID > $PIDFILE
|
|
|
|
sleep 1
|
2009-07-30 14:46:40 +02:00
|
|
|
echo "running with pid=$(cat $PIDFILE)" | tee -a $LOGFILE
|
2008-12-31 05:26:37 +01:00
|
|
|
fi
|
|
|
|
}
|
2007-11-13 04:50:41 +01:00
|
|
|
|
2008-12-31 05:26:37 +01:00
|
|
|
case $1 in
|
2007-11-13 04:50:41 +01:00
|
|
|
|
|
|
|
stop)
|
2008-12-31 05:26:37 +01:00
|
|
|
shift
|
2007-11-22 05:59:11 +01:00
|
|
|
if [ -f $PIDFILE ] && [ -f /proc/$(cat $PIDFILE)/exe ]; then
|
2007-11-13 04:50:41 +01:00
|
|
|
sync
|
2009-07-30 14:46:40 +02:00
|
|
|
echo "killing pid=$(cat $PIDFILE)" | tee -a $LOGFILE
|
2007-11-13 04:50:41 +01:00
|
|
|
kill $(cat $PIDFILE)
|
|
|
|
else
|
2009-07-30 14:46:40 +02:00
|
|
|
echo "not running or $PIDFILE not found" | tee -a $LOGFILE
|
2008-12-31 05:26:37 +01:00
|
|
|
PID=$(pidof xwrelay || true)
|
|
|
|
if [ "x${PID}" != "x" ]; then
|
2009-07-30 14:46:40 +02:00
|
|
|
echo "maybe it's $PID; killing them" | tee -a $LOGFILE
|
2008-12-31 05:26:37 +01:00
|
|
|
kill $PID
|
|
|
|
fi
|
2007-11-13 04:50:41 +01:00
|
|
|
fi
|
2008-12-31 05:26:37 +01:00
|
|
|
rm -f $PIDFILE
|
2007-11-13 04:50:41 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
restart)
|
2008-12-31 05:26:37 +01:00
|
|
|
shift
|
2007-11-13 04:50:41 +01:00
|
|
|
$0 stop
|
|
|
|
sleep 1
|
2007-11-22 05:59:11 +01:00
|
|
|
$0 start $@
|
2007-11-13 04:50:41 +01:00
|
|
|
;;
|
|
|
|
|
2008-12-31 05:26:37 +01:00
|
|
|
start)
|
|
|
|
shift
|
|
|
|
do_start $@
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
do_start $@
|
2007-11-13 04:50:41 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|