I have a task to design a service out of a bash script in order to be called in the way service ... start/stop/restart.The script that is to become a service is a infinite while loop which wakes up every minute and does some checking. I call it like this:start() {echo -n $Starting $DESC:DAEMON_ARGS=$(xmlstarlet sel -T -t -m /config/input/sensor/device/resource -v concat(../../@type, ' ', ../../@dev, ' ', @res) -n $CONFIGURATION_FILE | extract_devices)        # get device names out of XML fileecho daemon args $DAEMON_ARGSstart-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGSecho}pid and daemon are defined like this:PIDFILE=/var/run/detection.pidNAME=jblub_control_loop.shDAEMON=/root/test_det/${NAME}When I run./detection start (I also tried to copy into init.d and to run with service detection start)The init script simply doesn't get out of the loop and stays blocked in the start-stop-daemon function.When I comment out infinite while loop inside my jblub_control_loop.sh it passes but no pid file is created.My question is how to properly start script with an infinite loop as a service and why my pid file is not created.
start-stop-daemon blocks for process with infinite loop
start stop daemon
For a start, use the --background switch so it is forked.  use the -m switch to create a PID filestart-stop-daemon --start --background -m --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGSFor a copmplete answer, see https://stackoverflow.com/questions/16139940/what-is-start-stop-daemon-in-linux-scriptingEnjoy