Skip to content

Instantly share code, notes, and snippets.

@Propaganistas
Last active July 7, 2022 08:07
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 Propaganistas/e0123b5ec8665a1a38df to your computer and use it in GitHub Desktop.
Save Propaganistas/e0123b5ec8665a1a38df to your computer and use it in GitHub Desktop.
Cron daemon script
#!/bin/sh
#
# DO NOT MOVE THIS FILE, KEEP IN ROOT OF APPLICATION
#
# This file should be called by a Cron job every 5 minutes.
# It will call the Cron Queue and starts processing.
# Each call also checks if processing is already in progress
# (in case of a gigantic queue) and starts a new 'worker' with a maximum of 3.
# Command to call
COMMAND='/usr/bin/php /../../../artisan queue:work'
LOCKFILE=/../../../queueDaemon.lock
# -----------------------------------------------------
start() {
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "** Worker already running **"
else
echo "** Starting new worker **"
echo `cat ${LOCKFILE}`
rm -f ${LOCKFILE}
# Execute the command and write its PID into the lockfile.
$COMMAND & echo $! > ${LOCKFILE}
fi
return 0
}
stop() {
if [ -e ${LOCKFILE} ]; then
# Safely terminate the process found in the lockfile.
kill -15 `cat ${LOCKFILE}`
rm -f ${LOCKFILE}
echo "** Stopped worker **"
else
echo "** No worker available to stop **"
fi
return 0
}
restart() {
stop
echo "** Initiating startup **"
sleep 10s
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment