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

Also available in: Atom PDF