1
0
mirror of https://github.com/seahu/rflink.git synced 2025-12-10 16:07: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 # Description: This daemon will start 433 MHz control and sniffer and specialy used for Domoticz Home Automation System
### END INIT INFO ### END INIT INFO
dir="/opt/rflink"
cmd="./RFlink" DAEMON="/opt/rflink/RFlink"
config_file="/etc/rflink.conf"
# default config
user="" user=""
TCP_port=5050 TCP_port=5050
PIN_TX=28 PIN_TX=28
@@ -18,110 +21,46 @@ PIN_RX=29
log_level=1 log_level=1
log_file="" 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)
. /etc/rflink.conf if [ -f "$config_file" ]; then
. /etc/rflink.conf
fi
cmd="$cmd $TCP_port $PIN_TX $PIN_RX $log_level" . /lib/lsb/init-functions
cmd_to_syslog="$cmd_to_sysylog $TCP_port $PIN_TX $PIN_RX $log_level"
name=`basename $0` name=`basename $0`
pid_file="/var/run/$name.pid" PIDFILE="/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
}
case "$1" in case "$1" in
start) start)
if is_running; then
echo "Already started"
else
echo "Starting $name" 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 if [ -z "$log_file" ]; then
start_with_logger & start-stop-daemon -S -x $DAEMON -b -C -v -m -p $PIDFILE -- | logger -t $name &
else else
start_with_log_file & start-stop-daemon -S -x $DAEMON -b -C -v -m -p $PIDFILE -- >> $log_file
fi fi
echo $! > "$pid_file" else
if ! is_running; then if [ -z "$log_file" ]; then
echo "Unable to start, see $stdout_log and $stderr_log" start-stop-daemon -S -c $user -x $DAEMON -b -C -v -m -p $PIDFILE -- | logger -t $name &
exit 1 else
start-stop-daemon -S -c $user -x $DAEMON -b -C -v -m -p $PIDFILE -- >> $log_file
fi fi
fi fi
;; ;;
stop) stop)
if is_running; then echo -n "Stopping $name."
echo -n "Stopping $name.." #pkill -P `cat $PIDFILE`
killtree `get_pid` start-stop-daemon -K -x $DAEMON -p $PIDFILE --remove-pidfile
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
;; ;;
restart) restart)
echo -n "Restarting $name."
$0 stop $0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start $0 start
;; ;;
status) status)
if is_running; then start-stop-daemon -T -x $DAEMON
echo "Running"
else
echo "Stopped"
exit 1
fi
;; ;;
*) *)
echo "Usage: $0 {start|stop|restart|status}" echo "Usage: $0 {start|stop|restart|status}"

View File

@@ -112,6 +112,7 @@ for end connection type:
## Note ## Note
This tested only witch 433MHz receiver. And tested only with free aviable modules, full version contain much more no tested plugins. 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 ### Autor

View File

@@ -76,7 +76,7 @@ int TCPserver(int port)
log(LOG_ERROR,"TCP server: Problem add name to socket."); log(LOG_ERROR,"TCP server: Problem add name to socket.");
return -1; 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."); log(LOG_ERROR,"TCP server: Problem create reguest queue.");
return -1; return -1;

Binary file not shown.