troubleshooting Question

Custom script in startup causing boot hang - Ubuntu

Avatar of lunanat
lunanatFlag for Canada asked on
Shell ScriptingLinux Distributions
5 Comments1 Solution309 ViewsLast Modified:
So, as the subject says, I've written a script, and I've added it to my startup.

I have done so, using update-rc.d defaults 99

When I run the script manually, it works every time.  When I have it in any of the RC files (RC.2 for example) when the server boots, it starts all of the processes that it should (apache, openBSD sshd, etc) however then it hangs.  Usually I then see OpenBSD sshd restart, and there it sits.

I realize that most scripts have start and stop commands.. could this be all it is?  Script is attached as a code snippet, in case that is what is causing it.


function Sync {
	rsync -AErqz $othernode:/var/www /var
	rsync -AErqz $othernode:/etc/apache2/sites-available /etc/apache2/
	rsync -AEqz $othernode:/etc/apache2/*.conf /etc/apache2

ifup eth0 &> /dev/null
ifup eth0:1 &> /dev/null
ifdown eth0:1 &> /dev/null

thisnode=$(ifconfig | grep 'inet addr:' | grep -v '' | grep -v '' | cut -d: -f2 | awk '{ print $1}')
echo This node: $thisnode - $HOSTNAME
if [ $Node1 != $thisnode ]; then
echo othernode: $othernode

while [ 1 ];
	####If the node is primary, execute the primary functionality
	if [ -f /usr/ha/primary.var ]; then
		ifdown eth0:1
		/etc/init.d/apache2 start $> /dev/null
		echo Info - Assuming I am the primary node
		pingtest=$(ping -c 1 -I eth0 -W 5 $URL &> /dev/null)
		while [ $? = 0 ]; do
			echo - Warn - Shared IP Reachable
			if ! wget -T 5 -q -O /dev/null $URL:81 ; then
				echo - - CRIT - Web Server is not responsive, and I am suppposed to be primary
				echo Info - Webserver IS responsive\;  I thought I was supposed to be primary.
				echo - Warn - Stepping down to Secondary!
				touch /usr/ha/secondary.var
				rm /usr/ha/primary.var
			echo - Warn - Waiting...
			sleep 15
			pingtest=$(ping -c 1 -I eth0 -W 5 $URL &> /dev/null)
		if [ -f /usr/ha/primary.var ]; then
			echo Info - Shared IP is not reachable.  This is good.
			echo Info - Bringing up interface eth0:1
			ifup eth0:1
			arping -UA -c 3 -I eth0:1
		while [ -f /usr/ha/primary.var ]; do
			sleep 3
			pingtest=$(ping -c 1 -I eth0:1 -W 5
			if [ $? != 0 ]; then
				echo - - CRIT - My eth0:1 interface is down.  Stepping down to secondary.
				ifdown eth0:1
				touch /usr/ha/secondary.var
				rm /usr/ha/primary.var
	####If the node is secondary, execute the secondary functionality
	elif [ -f /usr/ha/secondary.var ]; then
		echo Info - Assuming I am the secondary node
		sleep 10
		ifdown eth0:1 &> /dev/null
		while [ 1 ]; do
			getvar=$(wget -T 5 -q -O /dev/null $URL:81)
			if [ $? != 0 ]; then
				echo Get FAILED
			#### WGET succeeded, rsync data as normal
			sleep 10
		#### WGET must have failed, if we reach this
		echo - - CRIT - I am secondary, but I cannot wget the website.  Taking charge!
		ssh $othernode touch /usr/ha/secondary.var
		ssh $othernode rm /usr/ha/primary.var
		ssh $othernode ifdown eth0:1
		touch primary.var
		rm secondary.var
	sleep 2
	echo Infinite Loop!  WOOOOO!!!

At the start I ifup and ifdown a bunch, because I want to guarentee that the virtual interface is stopped when the script is starting.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros