Created
January 9, 2022 05:28
-
-
Save jecxjo/48b2eb4c69999df7452d6157ecda60d3 to your computer and use it in GitHub Desktop.
Freebsd Daemonize script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Usage: daemonize.sh <pidfile> <exec> [<args>] | |
# | |
# Can be run from a cron job, will only trigger a single daemon to run | |
# and should restart the child daemon process if it fails. | |
usage() { | |
awk '/# Usage/{ x=1 } x==1 { print $0 } !/^#/ && x==1 { exit 0 }' $0 >&2 | |
exit 2 | |
} | |
if [ $# -lt 2 ] | |
then | |
usage | |
fi | |
PIDFILE="$1" | |
shift | |
EXEC="$1" | |
shift | |
if [ ! -e "$PIDFILE" ] | |
then | |
daemon -P "$PIDFILE" "$EXEC" $@ | |
exit 0 | |
else | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Coudn't one use FreeBSD's daemon?