From: realraum Date: Wed, 9 Sep 2009 23:14:30 +0000 (+0000) Subject: init script fuer c daemon X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=2d36bda2f28a3651d267affdf72c0ef1443cedec;p=svn42.git init script fuer c daemon --- diff --git a/checkcard.pl b/checkcard.pl index 263ffe7..cc1d1b7 100755 --- a/checkcard.pl +++ b/checkcard.pl @@ -3,9 +3,8 @@ use Socket; use strict; my $fh; -#my $fifofile = "/tmp/door_cmd.fifo"; -my $socketfile = "/tmp/door_cmd.socket"; +my $socketfile = $ARGV[0] || "/var/run/tuer/door_cmd.socket"; sleep(1) while (! -S $socketfile); my $socketaddr = sockaddr_un($socketfile); @@ -32,7 +31,7 @@ sub send_to_fifo while (sleep 1) { - open $fh,'/flash/tuer_python/mifare-read 0 2>&1 |'; + open $fh,'/flash/tuer/mifare-read 0 2>&1 |'; while (<$fh>) { next unless /UID/; diff --git a/tuer b/tuer index 063e1ac..46e9463 100755 --- a/tuer +++ b/tuer @@ -9,12 +9,27 @@ # Default-Stop: 1 ### END INIT INFO +EXE_DOOR=/flash/tuer/door_daemon +EXE_CARD=/flash/tuer/checkcard.pl +DIR_RUN=/var/run/tuer -test -f /flash/tuer_python/door_daemon.py || exit 0 -test -f /flash/tuer_python/checkcard.pl || exit 0 +DOOR_SOCKET=${DIR_RUN}/door_cmd.socket +DOOR_DEV=/dev/door +#DOOR_LOG=/var/log/tmp/tuer.log +DOOR_USR=tuer +DOOR_GRP=nogroup +#DOOR_HOME=$DIR_RUN -PIDFILE1=/var/run/door_daemon.pid -PIDFILE2=/var/run/checkcard.pid +PIDFILE1=${DIR_RUN}/door_daemon.pid +PIDFILE2=${DIR_RUN}/checkcard.pid + +test -f $EXE_DOOR || exit 1 +test -f $EXE_CARD || exit 1 +if [ ! -d $DIR_RUN ]; then + mkdir -p $DIR_RUN || exit 2 + chown -R $DOOR_USR:$DOOR_GRP $DIR_RUN +fi +chown $DOOR_USR:$DOOR_GRP $DOOR_DEV . /lib/lsb/init-functions @@ -25,15 +40,16 @@ PIDFILE2=/var/run/checkcard.pid case "$1" in start) log_daemon_msg "Starting door daemon" "door_daemon" - start-stop-daemon --start --quiet --pidfile $PIDFILE1 -b -m --name door_daemon.py --startas /flash/tuer_python/door_daemon.py -- + start-stop-daemon --start --quiet --pidfile $PIDFILE1 --name door_daemon --startas $EXE_DOOR -- -d $DOOR_DEV -s $DOOR_SOCKET -u $DOOR_USR -g $DOOR_GRP -P $PIDFILE1 log_end_msg $? log_daemon_msg "Starting door daemon" "checkcard" - start-stop-daemon --start --quiet --pidfile $PIDFILE2 -b -m --name checkcard.pl --startas /flash/tuer_python/checkcard.pl -- + start-stop-daemon --start --quiet --pidfile $PIDFILE2 -b -m --name checkcard.pl --startas $EXE_CARD -- $DOOR_SOCKET + #start-stop-daemon --start --quiet --pidfile $PIDFILE2 -c $DOOR_USR -b -m --name checkcard.pl --startas $EXE_CARD -- $DOOR_SOCKET log_end_msg $? ;; stop) log_daemon_msg "Stopping door daemon" "door_daemon" - start-stop-daemon --stop --quiet --pidfile $PIDFILE1 -m --name door_daemon.py + start-stop-daemon --stop --quiet --pidfile $PIDFILE1 -m --name door_daemon log_end_msg $? log_daemon_msg "Stopping door daemon" "checkcard" start-stop-daemon --stop --quiet --pidfile $PIDFILE2 -m --name checkcard.pl diff --git a/tuer_init_py b/tuer_init_py new file mode 100755 index 0000000..063e1ac --- /dev/null +++ b/tuer_init_py @@ -0,0 +1,51 @@ +#!/bin/sh +# Start/stop the tuer daemon. +# +### BEGIN INIT INFO +# Provides: tuer +# Required-Start: $remote_fs $syslog $time +# Required-Stop: $remote_fs $syslog $time +# Default-Start: 2 3 4 5 +# Default-Stop: 1 +### END INIT INFO + + +test -f /flash/tuer_python/door_daemon.py || exit 0 +test -f /flash/tuer_python/checkcard.pl || exit 0 + +PIDFILE1=/var/run/door_daemon.pid +PIDFILE2=/var/run/checkcard.pid + +. /lib/lsb/init-functions + +# Read the system's locale and set cron's locale. This locale +# will be inherited by cron (used to set charset of emails) +# and tasks running under it. + +case "$1" in +start) + log_daemon_msg "Starting door daemon" "door_daemon" + start-stop-daemon --start --quiet --pidfile $PIDFILE1 -b -m --name door_daemon.py --startas /flash/tuer_python/door_daemon.py -- + log_end_msg $? + log_daemon_msg "Starting door daemon" "checkcard" + start-stop-daemon --start --quiet --pidfile $PIDFILE2 -b -m --name checkcard.pl --startas /flash/tuer_python/checkcard.pl -- + log_end_msg $? + ;; +stop) + log_daemon_msg "Stopping door daemon" "door_daemon" + start-stop-daemon --stop --quiet --pidfile $PIDFILE1 -m --name door_daemon.py + log_end_msg $? + log_daemon_msg "Stopping door daemon" "checkcard" + start-stop-daemon --stop --quiet --pidfile $PIDFILE2 -m --name checkcard.pl + log_end_msg $? + killall "mifare-read" 2>/dev/null + ;; +restart) + $0 stop + $0 start + ;; +*) log_action_msg "Usage: $0 {start|stop|restart|reload|force-reload}" + exit 2 + ;; +esac +exit 0