mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2025-12-06 07:42:03 +01:00
add init script for useing BOSWatch as a daemon
see service/README.md for details
This commit is contained in:
parent
00902784a4
commit
249b3bbf53
28
service/README.md
Normal file
28
service/README.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
### Start BOSWatch as a daemon
|
||||
|
||||
## Changing the init script
|
||||
|
||||
Lines 14 and 15 define where to find the Python script.
|
||||
In this case the script expects that there is a folder `/usr/local/bin/BOSWatch` and that the script is inside there.
|
||||
|
||||
Line 23 sets what user to run the script as. Using root is generally not a good idea but might be necessary for BOSWatch.
|
||||
|
||||
Line 19 sets the parameters for BOSWatch, use the same as starting BOSWatch from the shell.
|
||||
We recommend to use "-u" and "-q" when you want to run BOSWatch as a daemon.
|
||||
- "-u": You will find the logfiles in `/var/log/BOSWatch`
|
||||
- "-q": Shows no information. Only logfiles
|
||||
|
||||
## Using the init script
|
||||
|
||||
To actually use this script, put your Python script where you want (recommend `/usr/local/bin/BOSWatch`)
|
||||
and make sure it is executable (e.g. `sudo chmod 755 boswatch.py`)
|
||||
Edit the init script accordingly. Copy the init script into /etc/init.d using e.g. `sudo cp boswatch.sh /etc/init.d`.
|
||||
Make sure the script is executable (chmod again) and make sure that it has UNIX line-endings.
|
||||
|
||||
At this point you should be able to start your Python script using the command `sudo /etc/init.d/boswatch.sh start`,
|
||||
check its status with the `sudo /etc/init.d/boswatch.sh status` argument and stop it with `sudo /etc/init.d/boswatch.sh stop`.
|
||||
|
||||
To make the Raspberry Pi use your init script at the right time, one more step is required:
|
||||
Running the command `sudo update-rc.d boswatch.sh defaults`.
|
||||
This command adds in symbolic links to the `/etc/rc.x` directories so that the init script is run at the default times.
|
||||
You can see these links if you do ls -l /etc/rc?.d/*myservice.sh
|
||||
62
service/boswatch.sh
Executable file
62
service/boswatch.sh
Executable file
|
|
@ -0,0 +1,62 @@
|
|||
#!/bin/sh
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: BOSWatch
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Python Service to receive and decode German BOS Information with rtl_fm and multimon-NG
|
||||
# Description: Python Service to receive and decode German BOS Information with rtl_fm and multimon-NG
|
||||
### END INIT INFO
|
||||
|
||||
# Change the next 3 lines to suit where you install your script and what you want to call it
|
||||
DIR=/usr/local/bin/BOSWatch
|
||||
DAEMON=$DIR/boswatch.py
|
||||
DAEMON_NAME=boswatch
|
||||
|
||||
# Add any command line options for your daemon here
|
||||
DAEMON_OPTS="-f xxx -a yyy -s zz -u -q"
|
||||
|
||||
# This next line determines what user the script runs as.
|
||||
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
|
||||
DAEMON_USER=root
|
||||
|
||||
# The process ID of the script when it runs is stored here:
|
||||
PIDFILE=/var/run/$DAEMON_NAME.pid
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
do_start () {
|
||||
log_daemon_msg "Starting system $DAEMON_NAME daemon"
|
||||
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS
|
||||
log_end_msg $?
|
||||
}
|
||||
do_stop () {
|
||||
log_daemon_msg "Stopping system $DAEMON_NAME daemon"
|
||||
start-stop-daemon --stop --pidfile $PIDFILE --retry 10
|
||||
log_end_msg $?
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
|
||||
start|stop)
|
||||
do_${1}
|
||||
;;
|
||||
|
||||
restart|reload|force-reload)
|
||||
do_stop
|
||||
do_start
|
||||
;;
|
||||
|
||||
status)
|
||||
status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
exit 0
|
||||
Loading…
Reference in a new issue