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)?
Asked
Active
Viewed 155 times
1 Answers
1
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.

Ruslan
- 395
- 3
- 12
-
option 1 will be just fine for my case. will also look in option 2. thank you for the complete answer :) – csaggo Mar 05 '18 at 07:02
-
@csaggo I have the same case, but still don't understand how the option1 works, have you added some code logic to your app? can you please share what you've done? – medBouzid Jul 22 '18 at 14:30
-
@medBo in my case im running a php-script. In the script i was able to get the above noted values with statement getenv('MASTER_HOST') for example. That you can compare to the current hostname so i compare getenv('MASTER_HOST') to $currentNode = trim(exec('hostname')); (both values i cut at the first occurence of '-' because they are a little different afterwards, but i get nodeNNNN until first '-' in both. – csaggo Jul 23 '18 at 02:34
-
@Ruslan can't get the ENV['MASTER_HOST'] with passenger in jelastic :( do you have any idea? – medBouzid Jul 25 '18 at 12:58
-
-
@medBo your welcome! passenger is about ruby? i dont know ruby, but i assume there should be similar possibility to access env-vars. if not it could be done in an sh-script outside the application, so make the check in sh-script and let it start the actual app, when on master. i guess that would be a cleaner approach anyway as it keeps the actual app indepentend from hosting – csaggo Jul 25 '18 at 18:09
-
@csaggo yes am using ruby on rails and generally to access these env variables you just have to do ENV['MASTER_HOST'] but somehow with passenger it's not possible to access it like that. I need it inside the app because am using a library that turn ruby code to cron job so it avoids me the hassle of writing cron syntax – medBouzid Jul 25 '18 at 19:54
-
@medBo I suggest to start your own question about this topic - it will be clearer to understand your exact problem and help to solve it. – Damien - Layershift Jul 26 '18 at 08:27