Search code examples
jelastic

How can i limit cron to one node


When adding a node manually or via automatic horizontal scaling master node will be cloned. This means that also crontab will be cloned right? How can i avoid, that a cron starts on two or more nodes simultaneously (which usually is not intended)?


Solution

  • There are few possible ways:

    • Your script can understand that it's not the master node, so it can remove itself from the cron or just do nothing. Each node has information about the master node in the layer/nodeGroup.

      env | grep MASTER
      MASTER_IP=172.25.2.1
      MASTER_HOST=node153580
      MASTER_ID=153580

    • Disable cron via Cloud Scripting at onAfterScaleOut. Here is an example how to use this event.

    • Deploy software templates as custom docker images (even if you use a certified Jelastic template). Such images are not cloned during horizontal scaling, they are created from scratch.