The filtered out data from a MQTT live stream is dumped into a csv file named mqtt.csv
and the dumping process is done by executor_start_up_job.txt
which is written in BASH (has a shebang).
I want to make the dumping of the filter daemon, i.e. in the background, and also want to make it in so that every time the system is rebooted it is done automatically. So I've concluded to write an init.d script, and contents of my code is:
#!/bin/bash
set -x
requested_command=$1
start() {
/home/ed/start_up_job/executor_start_up_job.txt &
}
# Restart the Dump
stop() {
killproc executor_start_up_job.txt
echo
}
### main logic ###
case $requested_command in
start)
start
;;
stop)
stop
;;
status)
last_line=`cat mqtt.csv | tail -1`
echo "last print line: $last_line"
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Once I have inserted set -x
I get the following output:
+ ./MySQL_table_update_daemon.sh start
+ requested_command=start
+ start
+ exit 0
Q: If I can make this code to work, then I will place it into the /etc/init.d/
directory, so that it can work every time. However currently it does not work and the output without the set -x
the is nothing i.e it's as if I've just pushed enter in the terminal.
You need to remove the
exit 0
at the end of the script, otherwise it will quit everytime it is run.You can check out
cat /etc/init.d/skeleton
for an exemple of a working init.d script. (Probably overkill for what you want to do, but it can help with a few things).