1
0
mirror of https://github.com/seahu/rflink.git synced 2025-12-10 07:57:23 +01:00

change init.d script to use start-stop-daemon command

This commit is contained in:
Ondrej Lycka
2017-07-02 02:25:54 +02:00
parent 5ea736850c
commit 72ec4838fa
5 changed files with 36 additions and 96 deletions

Binary file not shown.

View File

@@ -9,8 +9,11 @@
# Description: This daemon will start 433 MHz control and sniffer and specialy used for Domoticz Home Automation System
### END INIT INFO
dir="/opt/rflink"
cmd="./RFlink"
DAEMON="/opt/rflink/RFlink"
config_file="/etc/rflink.conf"
# default config
user=""
TCP_port=5050
PIN_TX=28
@@ -18,110 +21,46 @@ PIN_RX=29
log_level=1
log_file=""
#include config file (may redefine TCP_port, log_level, log_file)
#include config file if exist (may redefine TCP_port, log_level, log_file)
if [ -f "$config_file" ]; then
. /etc/rflink.conf
fi
cmd="$cmd $TCP_port $PIN_TX $PIN_RX $log_level"
cmd_to_syslog="$cmd_to_sysylog $TCP_port $PIN_TX $PIN_RX $log_level"
. /lib/lsb/init-functions
name=`basename $0`
pid_file="/var/run/$name.pid"
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
killtree() {
local parent=$1 child
for child in $(ps -o ppid= -o pid= | awk "\$1==$parent {print \$2}"); do
killtree $child
done
kill $parent 2> /dev/null
}
start_with_logger() {
if [ -z "$user" ]; then
sudo $cmd | logger
else
sudo -u "$user" $cmd | logger
fi
}
start_with_log_file() {
if [ -z "$user" ]; then
sudo $cmd >> "$log_file"
else
sudo -u "$user" $cmd >> "$log_file"
fi
}
PIDFILE="/var/run/$name.pid"
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
#start-stop-daemon --start --verbose --background --pidfile $PIDFILE --make-pidfile --exec $DAEMON
if [ -z "$log_file" ]; then
start_with_logger &
start-stop-daemon -S -x $DAEMON -b -C -v -m -p $PIDFILE -- | logger -t $name &
else
start_with_log_file &
start-stop-daemon -S -x $DAEMON -b -C -v -m -p $PIDFILE -- >> $log_file
fi
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
else
if [ -z "$log_file" ]; then
start-stop-daemon -S -c $user -x $DAEMON -b -C -v -m -p $PIDFILE -- | logger -t $name &
else
start-stop-daemon -S -c $user -x $DAEMON -b -C -v -m -p $PIDFILE -- >> $log_file
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
killtree `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
echo -n "Stopping $name."
#pkill -P `cat $PIDFILE`
start-stop-daemon -K -x $DAEMON -p $PIDFILE --remove-pidfile
;;
restart)
echo -n "Restarting $name."
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
start-stop-daemon -T -x $DAEMON
;;
*)
echo "Usage: $0 {start|stop|restart|status}"

View File

@@ -112,6 +112,7 @@ for end connection type:
## Note
This tested only witch 433MHz receiver. And tested only with free aviable modules, full version contain much more no tested plugins.
This server accept only one connection at same time, mainly for to prevent colision.
### Autor

View File

@@ -76,7 +76,7 @@ int TCPserver(int port)
log(LOG_ERROR,"TCP server: Problem add name to socket.");
return -1;
}
if (listen(mainSocket, 10) == -1) // create reguest queue (max 10)
if (listen(mainSocket, 1) == -1) // create reguest queue (max 1)
{
log(LOG_ERROR,"TCP server: Problem create reguest queue.");
return -1;

Binary file not shown.