Last active
July 7, 2022 08:07
-
-
Save Propaganistas/e0123b5ec8665a1a38df to your computer and use it in GitHub Desktop.
Cron daemon 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 | |
# | |
# 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