Skip to content

Instantly share code, notes, and snippets.

@jecxjo
Created January 9, 2022 05:28
Show Gist options
  • Save jecxjo/48b2eb4c69999df7452d6157ecda60d3 to your computer and use it in GitHub Desktop.
Save jecxjo/48b2eb4c69999df7452d6157ecda60d3 to your computer and use it in GitHub Desktop.
Freebsd Daemonize script
#!/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
@lispstudent
Copy link

Coudn't one use FreeBSD's daemon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment