Project

General

Profile

Actions

Architecture #4711

closed

Replace complex cron one-liner with one script call

Added by Dennis Cabooter over 10 years ago. Updated almost 10 years ago.

Status:
Released
Priority:
N/A
Assignee:
Jonathan CLARKE
Category:
System integration
Target version:
Effort required:
Name check:
Fix check:
Regression:

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!


Subtasks 1 (0 open1 closed)

Architecture #5391: Replace complex cron one-liner with one script call (impl)ReleasedBenoît PECCATTE2014-08-14Actions
Actions #1

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?

Actions #2

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. :)

Actions #3

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.

Actions #4

Updated by Jonathan CLARKE over 10 years ago

  • Status changed from 14 to 12
Actions #5

Updated by Jonathan CLARKE about 10 years ago

  • Status changed from 12 to Pending release
Actions #6

Updated by Matthieu CERDA about 10 years ago

  • Target version changed from 140 to 3.0.0~beta1
Actions #7

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.

Actions

Also available in: Atom PDF