Prevent shutdown until script finished - Raspberry Pi Forums


i have several scripts executing on pi, , don't want pi able shutdown until these scripts have finished executing. i've read using old init.d system, i'm struggling them work on jessie.

init.d script follows:

code: select all

#! /bin/bash  ### begin init info # provides:				program-name # required-start:		$remote_fs $syslog # required-stop:		$remote_fs $syslog # default-start:		2 3 4 5 # default-stop:			0 1 6 # short-description:	short-description # description:			long-description ### end init info   case "$1" in   stop) 	while pidof -x "/path/to/myscript" >/dev/null 	do 		echo "script still running..." 		sleep 10 	done esac  exit 0
idea script run when pi shuts down, , halt shutdown procedure until script /path/to/myscript had finished running.

mentioned above, couldn't work jessie - init.d script never called when system shut down or rebooted. i'm presuming it's because we're using systemd - i'm unsure of how systemd script achieve same init.d 1 above.

point me in right direction?

what want use handler 'catch' -sigterm signal ...

... when system shuts down sigterm issued processes signalling them system going down , whatever cleanup necessary , close. if process catches signal can prevent shutdown until finishes (closes files) , exits.

aware sigstop , sigkill cannot caught. depending how system goes down there nothing process can it... kill -sigkill <process number> , good-bye procees number.

there many examples of signal handling codes on net...


raspberrypi



Comments