summary refs log tree commit diff
path: root/bin/once
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2021-04-22 13:20:46 +0200
committerRobert Günzler <r@gnzler.io>2021-04-26 02:09:48 +0200
commit1b91d0296e5e6548147fb2e4adb245f597cb38ae (patch)
treeea6a9e3f125dc65be7e38479b101c32a5b9cb0fd /bin/once
parentca0a0d77da6516cea5a6b1790f9d68f628677ba7 (diff)
bin/once: add -r to restart service
Diffstat (limited to 'bin/once')
-rwxr-xr-xbin/once19
1 files changed, 18 insertions, 1 deletions
diff --git a/bin/once b/bin/once
index f13aecc..1655368 100755
--- a/bin/once
+++ b/bin/once
@@ -3,11 +3,14 @@
 set -e
 [ -n "$DEBUG" ] && set -x
 
+_check_running=
 ssd_args="--background --make-pidfile --start"
-while getopts Kkl:h opt; do
+while getopts rsKkl:h opt; do
 	case "$opt" in
 	K|k)   ssd_args='--stop';;
 	l)     ssd_args="${ssd_args} --stdout ${OPTARG} --stderr ${OPTARG}";;
+	s)     _check_running=1 ;;
+	r)     _restart=1 ;;
 
 	h)
 		printf "usage: %s [-h]\n" "$(basename "$0")"
@@ -24,6 +27,20 @@ exec="${1:-}"
 [ -z "${exec}" ] && exit 1
 shift
 
+if [ -n "$_check_running" ]
+then
+	[ -f "${XDG_RUNTIME_DIR}/${exec}.pid" ] && exit 0
+	exit 1
+fi
+
+if [ -n "$_restart" ]
+then
+	set -x
+	${0} -k ${exec} ${@}
+	${0} ${exec} ${@}
+	exit 0
+fi
+
 start-stop-daemon \
 	--pidfile "${XDG_RUNTIME_DIR:-/tmp}/${exec}.pid" \
 	$ssd_args \