1
Our production server is running into an issue with cron. Cron is set to execute every 5 minutes which works most of the time, however I am encountering an issue whereby a job may take 6 minutes to process. A second 6 minute job won't be actioned until 10 minutes has passed and sooner or later this is going to be a problem.
I've investigated writing a forking Daemon in C to listen for incoming requests -but this too is problematic because it would mean writing another API endpoint and chew into development time.
I've found what appears to be a simple solution, and am looking for criticism/critique:
for simplicities sake, a php CLI will output a 1 or a 0 depending whether there's a job waiting:
<?php echo "1" ?>
A bash script is able to check if there are any jobs in the queue:
#!/bin/bash
var=$(php -f ../readPhpOutput/testOutput.php)
if [ "$var" -eq "0" ]
then
echo "input zero"
else
echo "input not zero"
fi
sleep 10
Another bash script is running with nohup to ensure the above script is running:
#!/bin/bash
while true
do
value=$(ps -A | grep [r]eadPhpOutput)
echo "grep output is: $value"
if [ -z "$value" ]
then /bin/bash ../readPhpOutput/./readPhpOutput.sh &
fi
sleep 5
done
Please note the above are simple, naive examples to illustrate what I am trying to achieve.
My main reasons for not wanting to write a daemon are inexperience with C, fear of fork bombing my production server, and a reluctance to install a compiler on the same server.
1Your 2nd script basically reinvents a service manager, poorly. Existing software such as systemd, supervisord, monit can do the same thing. – user1686 – 2017-12-20T08:47:24.930
Thank you -this is precisely the kind of information I seek. It is pretty clear that I am out of my comfort zone :) – pcgben – 2017-12-20T08:49:11.113
Note that you don't need to install a compiler on the server. You can compile programs on another machine, and copy only the binary executable to the server. – janos – 2017-12-20T08:53:56.867