summary refs log tree commit diff
path: root/bin/once
blob: f13aecc7cee40a37ad1da3cca3aec208a18aca97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

set -e
[ -n "$DEBUG" ] && set -x

ssd_args="--background --make-pidfile --start"
while getopts Kkl:h opt; do
	case "$opt" in
	K|k)   ssd_args='--stop';;
	l)     ssd_args="${ssd_args} --stdout ${OPTARG} --stderr ${OPTARG}";;

	h)
		printf "usage: %s [-h]\n" "$(basename "$0")"
		printf "\n"
		printf "  -K -k          kill the service\n"
		printf "     -l LOGFILE  log to a file\n"
		printf "\n"
		exit 2 ;;
	esac
done
shift $((OPTIND - 1))

exec="${1:-}"
[ -z "${exec}" ] && exit 1
shift

start-stop-daemon \
	--pidfile "${XDG_RUNTIME_DIR:-/tmp}/${exec}.pid" \
	$ssd_args \
	"${exec}" -- "${@}"