I have two identically configured CentOS 5 servers (possibly more in the future). I need to run a cron job on any one of them and that it'll run only on one of them.
I know about RedHat Cluster Suite (we use it on other servers), but it's a too big a gun to use for this task, plus it doesn't really behave well for less than three nodes.
Is there anything light-weight I can use for that?
The servers can communicate with each other directly. I suppose I can develope something over ssh or nrpe (two server which are already installed on these servers), but I was wondering whether there is something already available.
For enterprise solutions you can use BMC Control-M. An open source alternative would be Job Scheduler
This is pretty simple to do with a lockfile on a shared filesystem like NFS. I'm assuming however you don't have that setup.
Here's a few ideas that come to mind:
Implement a lock on some shared resource, or something that both machines can access. For example, can they both write to some external network resource? Downside: lots of opportunities for race conditions I'm sure.
Use the readhat DLM and access locking via perl DLM::Client. Downside: as you mention, might be more heavyweight than you want.
Try the ruby lockserver Officer. Might be fun if you're in to ruby.
Here's another perl distributed locking mechanism: IPC::Locker. Advantage: doesn't require you to set up another service like the linux kernel DLM.
Use a messaging service like RabbitMQ to do locking. Again, probably pretty heavyweight.
I'm a perl programmer myself, so I'l probably try IPC::Locker first. I like the simplicity of that approach if you just have two servers.