Page 1 of 1

Need to stop/bypass a looping startup process

Posted: Mon Jan 06, 2014 7:57 pm
by jimmybobby
Ok, so am new to the forum, please bear that in mind.

Anyway, I have generated a python script that uses

Code: Select all

while True
ok, and that runs at startup, in

Code: Select all

/etc/init.d/ScriptName
I was using this tutorial: http://www.stuffaboutcode.com/2012/06/r ... rt-up.html
And I forgot to include this code:

Code: Select all

### BEGIN INIT INFO
# Provides:          noip
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO
Or the equivalent for my purpose, so now, it starts at boot time, and it seems to run before SSH, Apache, or FTP is initiated... so I cannot re-correct the mistake to run the program after these services are started...
Is there any way I can correct this error?

I only wanted to start the looping script at boot!

Re: Need to stop/bypass a looping startup process

Posted: Mon Jan 06, 2014 9:06 pm
by jimmybobby
Can I just add, it is absolutely essential that I do not have to start over - I have no backups of my scripts, and it would be a massive pain to have to reformat the sd card.

Re: Need to stop/bypass a looping startup process

Posted: Mon Jan 06, 2014 9:48 pm
by Douglas6
And you can't simply kill the process? Or edit the code and reboot? If all else fails, there's always safe mode. It saved my cookies the other day when I ended up with 'sudo halt' in my rc.local startup script (don't ask). Do be careful jumpering those pins. The wrong ones and you'll be a sad puppy.

Step 2. Make a backup. :) Wait. Make that step one. And then step three.

Re: Need to stop/bypass a looping startup process

Posted: Mon Jan 06, 2014 9:52 pm
by DougieLawson
It may be easier to boot the RPi from another card and mount the borked card in a USB SDCard reader.

Or boot your laptop from Knoppix (CD/DVD based Linux system), mount the borked SDCard and you can fix it.

My Fuji USB SDCard reader is the most useful thing in my toolbox. It's certainly a lot less risky than connecting pins to get into safe mode.

Re: Need to stop/bypass a looping startup process

Posted: Tue Jan 07, 2014 1:31 pm
by jimmybobby
DougieLawson wrote:It may be easier to boot the RPi from another card and mount the borked card in a USB SDCard reader.

Or boot your laptop from Knoppix (CD/DVD based Linux system), mount the borked SDCard and you can fix it.

My Fuji USB SDCard reader is the most useful thing in my toolbox. It's certainly a lot less risky than connecting pins to get into safe mode.

Oh if only I had a USB SD Card reader; I use the inbuilt reader on my PC!

Damn!



Will try safe mode, what exactly does it do?
Can I still access

Code: Select all

/etc/rc.local/
from safe mode, or the emergency kernel image?

Re: Need to stop/bypass a looping startup process

Posted: Tue Jan 07, 2014 1:55 pm
by Richard-TX
What you needed to do was this:

Write your forever looping program as a separate shell script.

In the startup or rc.local script you put this:

nohup /root/myloop &

Now all is safe.

If you loop a startup script itself, it will never complete the boot process.

You need nohup because the parent process will exit and when the parent dies, so do the children.

Re: Need to stop/bypass a looping startup process

Posted: Tue Jan 07, 2014 4:09 pm
by jojopi
jimmybobby wrote:Will try safe mode, what exactly does it do?
Can I still access /etc/rc.local/ from safe mode, or the emergency kernel image?
Safe mode does not automatically mount the Raspbian root filesystem, and it has a limited selection of commands and editors available. After booting, remove the jumper, hit enter to get a prompt, and run:

Code: Select all

mount /dev/mmcblk0p2 /mnt
mv /mnt/etc/rc.local /mnt/etc/rc.local.broken
reboot
Then you can edit and rename the file back in the main system. If you installed using NOOBS, the Raspban root will probably be /dev/mmcblk0p6, instead of p2.

edit: If you meant /etc/init.d/something, then the easiest fix is to remove the start links from all runlevels: "rm /mnt/etc/rc?.d/S*something".
Richard-TX wrote:You need nohup because the parent process will exit and when the parent dies, so do the children.
When a shell exits, any background jobs continue and are inherited by init. It is your responsibility to kill them if you do not want that.

"nohup" is intended for the situation where a session may disconnect unexpectedly, by telephone hangup, rather than shell exit. It redirects input from /dev/null and output to nohup.out. Even then it is usually unnecessary, because hangup signals are sent only to the foreground process group, and dash does not pass the signal on to background jobs at all, and bash often crashes due to loss of terminal before it even sees the signal.

Re: Need to stop/bypass a looping startup process

Posted: Tue Jan 07, 2014 4:50 pm
by jimmybobby
Ok, am going to try this now,

I had looped a startup script, and so that was the problem, because in my 'rc.local' I had put something like

Code: Select all

(python /home/pi/FOLDERNAME/SCRIPTNAME.py )&
which contained the

Code: Select all

while True
line, so, it was in essentials, looping a startup script.


Will post what does, and does not work!


Thanks for your responses - they have all been of use to me!

Re: Need to stop/bypass a looping startup process

Posted: Tue Jan 07, 2014 4:53 pm
by jimmybobby
jojopi wrote: edit: If you meant /etc/init.d/something, then the easiest fix is to remove the start links from all runlevels: "rm /mnt/etc/rc?.d/S*something".
Yes, this is what I meant.

Re: Need to stop/bypass a looping startup process

Posted: Tue Jan 07, 2014 5:57 pm
by jimmybobby
jojopi wrote:
jimmybobby wrote:Will try safe mode, what exactly does it do?
Can I still access /etc/rc.local/ from safe mode, or the emergency kernel image?
Safe mode does not automatically mount the Raspbian root filesystem, and it has a limited selection of commands and editors available. After booting, remove the jumper, hit enter to get a prompt, and run:

Code: Select all

mount /dev/mmcblk0p2 /mnt
mv /mnt/etc/rc.local /mnt/etc/rc.local.broken
reboot
Then you can edit and rename the file back in the main system. If you installed using NOOBS, the Raspban root will probably be /dev/mmcblk0p6, instead of p2.

edit: If you meant /etc/init.d/something, then the easiest fix is to remove the start links from all runlevels: "rm /mnt/etc/rc?.d/S*something".
Richard-TX wrote:You need nohup because the parent process will exit and when the parent dies, so do the children.
When a shell exits, any background jobs continue and are inherited by init. It is your responsibility to kill them if you do not want that.

"nohup" is intended for the situation where a session may disconnect unexpectedly, by telephone hangup, rather than shell exit. It redirects input from /dev/null and output to nohup.out. Even then it is usually unnecessary, because hangup signals are sent only to the foreground process group, and dash does not pass the signal on to background jobs at all, and bash often crashes due to loss of terminal before it even sees the signal.
So, will I need to copy this back to its location originally, to enable headless operation (ssh and ftp etc) because it works connected to monitor and keyboard etc, but I can't connect to ssh, and the pi is not online according to my router (to which it is directly connected by ethernet)

If I do need to do this, how do I replace /mnt/etc/rc.local.broken easily, without running into the original problem again?

Re: Need to stop/bypass a looping startup process

Posted: Tue Jan 07, 2014 6:56 pm
by jimmybobby
Ok, never mind, have copied off of it the files I need, and so am reformatting the SD card, and setting it up again.

Re: Need to stop/bypass a looping startup process

Posted: Tue Jan 07, 2014 6:59 pm
by jojopi
jimmybobby wrote:So, will I need to copy this back to its location originally, to enable headless operation (ssh and ftp etc) because it works connected to monitor and keyboard etc, but I can't connect to ssh, and the pi is not online according to my router (to which it is directly connected by ethernet)

If I do need to do this, how do I replace /mnt/etc/rc.local.broken easily, without running into the original problem again?
Not sure I understand the questions. Safe mode has no networking, so you need a local screen and keyboard to do the initial fix that way. Otherwise your best option is to mount the card on another Linux system; either another Raspbian install on a second SD card and mount the original in a USB card reader, or a LiveDVD/LiveUSB distro on a PC.

/etc/rc.local comes too late in the boot sequence to break SSH; it can only prevent console logins. /etc/init.d/yourscript is not run directly; instead, there are symlinks called /etc/rc?.d/S??yourscript that indicate which runlevels to start it in, and in what sequence. Once you delete those links and remove the safe mode jumper the card should boot normally again, with SSH.

To fix the script permanently you need to put the python command in the background ("python script.py &"), preferably add a "BEGIN INIT INFO" block with "Required-Start: ssh" so that the script is run later in the sequence, and then re-run the update-rc.d command to create the new S links.

However, according to some of your posts the python command is already in the background, starts from /etc/rc.local, and only breaks SSH, not the console? If any of those are true then we have not diagnosed your problem correctly.

Re: Need to stop/bypass a looping startup process

Posted: Wed Jan 08, 2014 7:03 pm
by jimmybobby
jojopi wrote:
jimmybobby wrote:So, will I need to copy this back to its location originally, to enable headless operation (ssh and ftp etc) because it works connected to monitor and keyboard etc, but I can't connect to ssh, and the pi is not online according to my router (to which it is directly connected by ethernet)

If I do need to do this, how do I replace /mnt/etc/rc.local.broken easily, without running into the original problem again?
Not sure I understand the questions. Safe mode has no networking, so you need a local screen and keyboard to do the initial fix that way. Otherwise your best option is to mount the card on another Linux system; either another Raspbian install on a second SD card and mount the original in a USB card reader, or a LiveDVD/LiveUSB distro on a PC.

/etc/rc.local comes too late in the boot sequence to break SSH; it can only prevent console logins. /etc/init.d/yourscript is not run directly; instead, there are symlinks called /etc/rc?.d/S??yourscript that indicate which runlevels to start it in, and in what sequence. Once you delete those links and remove the safe mode jumper the card should boot normally again, with SSH.

To fix the script permanently you need to put the python command in the background ("python script.py &"), preferably add a "BEGIN INIT INFO" block with "Required-Start: ssh" so that the script is run later in the sequence, and then re-run the update-rc.d command to create the new S links.

However, according to some of your posts the python command is already in the background, starts from /etc/rc.local, and only breaks SSH, not the console? If any of those are true then we have not diagnosed your problem correctly.

Whatever the case, the information collected here appears to have enabled me to access the "startx" desktop on a monitor etc, and I have taken the files from it, and put them onto a new fresh Raspbian OS (Which needed updating anyway), so - the old errors are not a problem, and I will just use the "screen" package, which I think is apt-get install screen, if memory serves me correctly, and that will run while not logged into ssh - which is fine for my current usage.


I thank everyone involved in this thread for your support.


(In case you were wondering what I was doing in the grand scheme of things, I was getting a random password generator to post to twitter every 60 seconds (roughly, as generating the password takes a couple of seconds - don't ask) etc...
If you really wanted to see the product you have helped me make, just go to https://twitter.com/RPiPasswordGen to go to the twitter page.