Architecture #4711
closedReplace complex cron one-liner with one script call
Description
Please replace this:
$ tail -1 /etc/cron.d/rudder-agent 0,5,10,15,20,25,30,35,40,45,50,55 * * * * root . /etc/profile; if [ -e /opt/rudder/bin/check-rudder-agent ]; then /opt/rudder/bin/check-rudder-agent; else if [ ! -e /opt/rudder/etc/disable-agent -a `ps -efww | grep -E "(cf-execd|cf-agent)" | grep -E "/var/rudder/cfengine-community/bin/(cf-execd|cf-agent)" | grep -v grep | wc -l` -eq 0 ]; then /var/rudder/cfengine-community/bin/cf-agent -f failsafe.cf >/dev/null 2>&1 && /var/rudder/cfengine-community/bin/cf-agent >/dev/null 2>&1; if [ $? != 0 ]; then if [ -f /opt/rudder/etc/rudder-restart-message.txt ]; then cat /opt/rudder/etc/rudder-restart-message.txt; else echo "Rudder agent was unable to restart on $(hostname)."; fi; fi; fi; fi
with something more readable to prevent typos.
Like this:
$ tail -1 /etc/cron.d/rudder-agent 0,5,10,15,20,25,30,35,40,45,50,55 * * * * root /opt/rudder/bin/rudder-cron.sh $ cat /opt/rudder/bin/rudder-cron.sh #!/bin/bash # # Source profile file . /etc/profile # Do checks if [ -e /opt/rudder/bin/check-rudder-agent ]; then /opt/rudder/bin/check-rudder-agent elif [ ! -e /opt/rudder/etc/disable-agent -a `ps -efww | grep -E "(cf-execd|cf-agent)" | grep -E "/var/rudder/cfengine-community/bin/(cf-execd|cf-agent)" | grep -v grep | wc -l` -eq 0 ]; then /var/rudder/cfengine-community/bin/cf-agent -f failsafe.cf >/dev/null 2>&1 && /var/rudder/cfengine-community/bin/cf-agent >/dev/null 2>&1 if [ $? != 0 ]; then if [ -f /opt/rudder/etc/rudder-restart-message.txt ]; then cat /opt/rudder/etc/rudder-restart-message.txt else echo "Rudder agent was unable to restart on $(hostname)." fi fi fi
NOTE: I did not check the script for errors and I'm not sure what it should to. This is only an example. Have fun!
Updated by Vincent MEMBRÉ over 10 years ago
- Category set to System integration
- Status changed from New to Discussion
- Assignee set to Jonathan CLARKE
That's a wonderful idea Dennis, and really much more readable.
I dont knwo it which version this should come ... That's a rather big change and I would have done it in next major release (2.11)
Jon what do you think of it?
Updated by Dennis Cabooter over 10 years ago
I don't think its a big change. It's really unreadable now and I would implement it in 2.10 and backport it to all versions of Rudder that have this cron. Oneliners shouldn't be this long! Just my 2 cents. :)
Updated by Jonathan CLARKE over 10 years ago
- Tracker changed from Bug to Architecture
- Subject changed from Replace cron line with script to Replace complex cron one-liner with one script call
- Status changed from Discussion to 14
- Target version set to 140
This is already the direction that this cron script is going in. If you read carefully, you will see that the only thing this cron does is check if the script /opt/rudder/bin/check-rudder-agent exists and run it. The "else" part is for backwards compatibility.
This new script (/opt/rudder/bin/check-rudder-agent) was introduced in Rudder 2.6. Since 2.11+ only support upgrades from 2.6+, we can now safely remove this.
I will update the cron script to be released in 2.12.
Updated by Jonathan CLARKE about 10 years ago
- Status changed from 12 to Pending release
Updated by Matthieu CERDA about 10 years ago
- Target version changed from 140 to 3.0.0~beta1
Updated by Vincent MEMBRÉ almost 10 years ago
- Status changed from Pending release to Released
This bug has been fixed in Rudder 3.0.0~beta1 which was release on 01/12/2014.
- Announcement
- Changelog
- Download information: https://www.rudder-project.org/site/get-rudder/downloads/