SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


redhatmercurial
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
redhatmercurial [2015/01/28 15:47]
sjoerd
redhatmercurial [2015/01/28 15:57] (current)
sjoerd
Line 503: Line 503:
 </​code>​ </​code>​
  
 += Script for Automatic Updates =
 +I also wanted a script so I could create changes to configfiles without having to thing about committing these changes to the repository. Downside of this is of course that if you would have multiple edits on the same file between updates these updated would go missing. Do mitigate this you should run your script as often as possible, or only change files on one server. I created a script that can be scheduled using cron.
  
 +== Script ==
 +<code bash>
 +# Script to update changes in the adminscripts directory and distribute them among all the servers.
 +# Author: Sjoerd Hooft
 +# Date: 27-11-2014
 +
 +# Schedule time
 +# This script can be used manually or scheduled. To make sure changes are not pushed at the same time keep this schedule:
 +# 3:00 rhmgmtsrv01
 +# 3:05 rhmgmtsrv02
 +# 4:00 rhdbprd01
 +# 4:05 rhapprd01
 +# 5:00 rhdbacp01
 +# 5:05 rhapacp01
 +
 +# Script Variables
 +TODAY=`date +%Y%m%d%H%M`
 +LOGFILE=/​tmp/​mercurialdailyupdate.log
 +HOST=`hostname -s`
 +REPO="/​adminscripts/"​
 +
 +# Create new logfile
 +echo "Start daily mercurial update on $HOST on $TODAY"​ > $LOGFILE
 +
 +# First: Push local changes to the repository
 +echo "Start push" >> $LOGFILE
 +/usr/bin/hg add -R $REPO >> $LOGFILE
 +/usr/bin/hg commit -u "​DailyPush"​ -m "​DailyPush"​ -R $REPO >> $LOGFILE
 +/usr/bin/hg push -R $REPO >> $LOGFILE
 +
 +# Second: download changes from other servers
 +echo "Start pull" >> $LOGFILE
 +/usr/bin/hg pull -R $REPO >> $LOGFILE
 +/usr/bin/hg update -R $REPO >> $LOGFILE
 +
 +# Close
 +echo "End of log" >> $LOGFILE
 +exit 0
 +</​code>​
 +
 +== Cron ==
 +Then schedule the script using {{{sudo crontab -e}}} (so the script gets executed as root):
 +<​code>​
 +# Run mercurial update every day (time in script)
 +0 3 * * * /​adminscripts/​mercurialupdate > /​tmp/​mercurialupdate.log 2>&1
 +</​code>​
  
 = Resources = = Resources =
Line 513: Line 561:
 http://​hgbook.red-bean.com/​read/​finding-and-fixing-mistakes.html \\ http://​hgbook.red-bean.com/​read/​finding-and-fixing-mistakes.html \\
  
-{{tag>​redhat linux}}+{{tag>​redhat linux scripts}}
  
redhatmercurial.txt ยท Last modified: 2015/01/28 15:57 by sjoerd