'Scheduled tasks (cronjobs) how to do that on one server only

I have a PHP solution where a number of tasks run every minute with cronjobs (wget URL's on server).

That is all fine, but I would like to be able to launch multiple instances behind a load balancer of the same server (AWS Instance Template), and I need a way to make sure that only one server runs the cronjobs, no matter if more instances are launched.

Is there a way to "nominate" one as main server (only one runs the cronjobs) and still only use one single Instance Template (Image) for launching new servers?

I have full control over the source code, so a solution in PHP is fine (prefereable).

I would like to avoid to manually have to edit/deploy crontab for a "special" server, so they could all be alike.

I don't think that a "State" in for example the database will work, since they will all be EC2 instances, and therefor the execution of the cronjobs will kick in at more or less the exact same microsecond across the servers.



Solution 1:[1]

you can try something like this: https://github.com/incapption/LoadBalancedCronTask

It distributes your cron jobs around the nodes and lets you run local jobs as well

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris