LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-04-2010, 10:04 AM   #1
zensunni
Member
 
Registered: Feb 2008
Posts: 45

Rep: Reputation: 0
Script causes Ubuntu to hang on shutdown


I've got a bash script that is started at startup and always runs in the background & is running on an infinite loop.

But, it makes the OS hang on shutdown.

Is there any simple way to eliminate the hang while keeping the script?
 
Old 12-04-2010, 10:11 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by zensunni View Post
But, it makes the OS hang on shutdown.
That should not be possible ... maybe unless it hangs the init runlevel change. How are you starting it? Try putting an & at the end of the command line that starts it to ensure that the script that calls it continues.
 
1 members found this post helpful.
Old 12-04-2010, 12:41 PM   #3
zensunni
Member
 
Registered: Feb 2008
Posts: 45

Original Poster
Rep: Reputation: 0
Your suggestion worked, but I can't make sense of this:

If I add the "&" and shutdown AFTER starting it up without the "&", it won't hang.
And if I delete the "&" and shutdown AFTER starting it up with the "&", it will hang.

Shouldn't the script's edits take effect AFTER I shutdown and reboot?

..so weird. Anyways, the problem is solved, save for the sequential mysteries. Thanks for the help.
 
Old 12-04-2010, 06:34 PM   #4
gd2shoe
Member
 
Registered: Jun 2004
Location: Northern CA
Distribution: Debian
Posts: 835

Rep: Reputation: 49
We still don't know how you're starting your script.

Maybe the script is getting started during shutdown for some reason?
 
Old 12-05-2010, 05:08 AM   #5
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,093

Rep: Reputation: 197Reputation: 197
Quote:
Originally Posted by zensunni View Post
If I add the "&" and shutdown AFTER starting it up without the "&", it won't hang.
And if I delete the "&" and shutdown AFTER starting it up with the "&", it will hang.
You don't give any indication of where you are adding or removing the &, but I'm thinking the script call repeatedly calls itself. Is that the case? If so, the behaviour you describe possibly be eliminated by calling the script once and wrapping it in a do while
Code:
while true;do

you script here

done
It will probably help if you post both the script and the script which is calling the script, if there is one.
 
Old 12-05-2010, 09:33 AM   #6
zensunni
Member
 
Registered: Feb 2008
Posts: 45

Original Poster
Rep: Reputation: 0
Yes, I should definitely be more specific about this. There's a lot I left out.

Here's the scripts in question:

after_hours_root.sh
Code:
#!/bin/bash

for (( ; ; ))
do

   z_hr=`date +%H`
   echo $z_hr
   if [ $z_hr -gt 21 ] || [ $z_hr -lt 5 ]; then 
        sleep 960
   	/sbin/shutdown -h now
   else
	sleep 600
   fi


done
after_hours_user.sh
Code:
#!/bin/bash

export DISPLAY=:0.0;
export  XAUTHORITY=$(ps h $(pidof X) | awk '{print $11}');


for (( ; ; ))
do

   z_hr=`date +%H`
   if [ $z_hr -gt 21 ] || [ $z_hr -lt 5 ]; then 
   	/usr/bin/xmessage -button ok -center "Its too late to be on the computer. You have 15 minutes." &
        sleep 900
   	/usr/bin/xmessage -button ok -center "1 minute to Shutdown" &
	sleep 600
   else
	sleep 600
   fi

done
hourly_reminder.sh
Code:
#!/bin/bash

export DISPLAY=:0.0;
export  XAUTHORITY=$(ps h $(pidof X) | awk '{print $11}');

for (( ; ; ))
do

   sleep 3600
   #sleep 3
   /usr/bin/xmessage -button ok -center "Hourly reminder to get off the computer"

done
(I made two files named hourly reminder: starter script & the above one.)

And here's the script that starts it:

hourly_reminder.sh
Code:
sleep 60

/bin/su - joe -c "/bin/bash /home/joe/Scripts/hourly_reminder.sh" &
/bin/su - joe -c "/bin/bash /home/joe/Scripts/after_hours_user.sh" &
/bin/bash /home/joe/Scripts/after_hours_root.sh &
The line at the end...
Code:
/bin/bash /home/joe/Scripts/after_hours_root.sh &
...is where I have been adding and subtracting the "&".

The starter script is in /etc/init.d/

This is what I did when I added the starter script:
http://embraceubuntu.com/2005/09/07/...run-at-bootup/

(I'm not sure if the script is run because it's in the init.d folder, or because I used the "update-rc.d <script> defaults" command as per the guide above.)

Last edited by zensunni; 12-05-2010 at 09:37 AM.
 
Old 12-05-2010, 10:58 AM   #7
barriehie
Member
 
Registered: Nov 2010
Distribution: Debian Lenny
Posts: 136
Blog Entries: 1

Rep: Reputation: 23
Have you thought about rewriting your init script to be LSB compliant? I've pulled my hair out when the machine got hung on boot! Give this a try; it will, should, start/stop the involved scripts. This is the script that should go in /etc/init.d/nohangshutdownctl Here's a link to init scripts. It's from the Debain wiki but since you're using Ubuntu it should work. Pay attention to the paths; I habitually put system wide scripts in /usr/local/bin...
Code:
#!/bin/bash

### BEGIN INIT INFO
# Provides:          nohangonshutdownctl
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: nohangscripts start/stop control file.
### END INIT INFO


case "$1" in
    start)
	echo "Starting hourly_reminder.sh."
	/bin/su - joe -c "/usr/local/bin/hourly_reminder.sh &"
        echo "Starting after_hours_user.sh."
        /bin/su - joe -c "/usr/local/bin/after_hours_user.sh &"
        echo "Starting after_hours_root.sh"
        /bin/su - joe -c "/usr/local/bin/after_hours_root.sh &"
    ;;
    stop)
	echo "Shutting down process'."
	killall -s 9 hourly_reminder.sh after_hours_user.sh after_hours_root.sh
    ;;
    *)
	echo "Usage: $0 {start|stop}"
	exit 1
esac
exit 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shutdown hang of diskless node mortimer Linux - Enterprise 3 05-05-2013 11:48 AM
UBUNTU: can I run startup script only (not on shutdown)? fopetesl Linux - Software 8 06-10-2010 03:16 AM
gentoo shutdown hang Melz_Dark_Angel Linux - Software 1 08-19-2006 06:56 PM
shutdown hang during eth0 shutdown kurtisw Linux - Networking 5 10-30-2003 02:49 PM
PC seems to hang after shutdown. eNTi Slackware 2 09-09-2002 12:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration