Skip to content

Instantly share code, notes, and snippets.

@jfrazee
Last active August 14, 2021 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfrazee/1b137ebc70d89d7bceb6cfe08bbeb79e to your computer and use it in GitHub Desktop.
Save jfrazee/1b137ebc70d89d7bceb6cfe08bbeb79e to your computer and use it in GitHub Desktop.
fcron init script
#!/bin/sh
# This is based on the cron init script for vixie cron from Ubuntu 20.04 and the
# fcron.init.suse init script included with fcron which are licensed under the
# GPLv2 license.
### BEGIN INIT INFO
# Provides: fcron
# Required-Start: $remote_fs $syslog $time
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: fcron background program processing daemon
# Description: fcron is a periodical command scheduler which aims at
# replacing vixie cron. It makes no assumptions on whether
# your system is running all the time or regularly, making it
# ideal for laptops and workstations.
### END INIT INFO
set -e
# /etc/init.d/fcron: start and stop the fcron daemon
NAME=fcron
DAEMON=/usr/sbin/fcron
FCRONDYN=/usr/bin/fcrondyn
PIDFILE=/var/run/fcron.pid
FCRON_CONFIG=/etc/fcron.conf
FCRON_OPTS=''
test -f $DAEMON || exit 0
. /lib/lsb/init-functions
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
[ -r /etc/default/locale ] && . /etc/default/locale
if [ -z "$TZ" -a -e /etc/timezone ]; then
TZ="$(cat /etc/timezone)"
fi
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
# Remove $PIDFILE if it exists for some reason but is empty
test -e $PIDFILE && ! test -s $PIDFILE && rm $PIDFILE
case "$1" in
start)
log_daemon_msg "Starting periodic command scheduler" "$NAME"
if [ ! -s "$FCRON_CONFIG" ]; then
log_failure_msg "Configuration file $FCRON_CONFIG is empty or does not exist"
log_end_msg 1
exit 1
fi
start_daemon -p $PIDFILE $DAEMON $FCRON_OPTS
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping periodic command scheduler" "$NAME"
killproc -p $PIDFILE $DAEMON
RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
log_end_msg $RETVAL
;;
force-reload|restart)
$0 stop
sleep 3
$0 start
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
jobs)
$FCRONDYN -x ls | while read line; do
log_daemon_msg $line
done
;;
*) log_action_msg "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status|jobs}"
exit 2
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment