jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Need to stop/bypass a looping startup process

Mon Jan 06, 2014 7:57 pm

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!
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Need to stop/bypass a looping startup process

Mon Jan 06, 2014 9:06 pm

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.
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

User avatar
Douglas6
Posts: 4849
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Need to stop/bypass a looping startup process

Mon Jan 06, 2014 9:48 pm

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.
Last edited by Douglas6 on Mon Jan 06, 2014 9:57 pm, edited 1 time in total.

User avatar
DougieLawson
Posts: 38479
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Need to stop/bypass a looping startup process

Mon Jan 06, 2014 9:52 pm

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Need to stop/bypass a looping startup process

Tue Jan 07, 2014 1:31 pm

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?
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Need to stop/bypass a looping startup process

Tue Jan 07, 2014 1:55 pm

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.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
jojopi
Posts: 3190
Joined: Tue Oct 11, 2011 8:38 pm

Re: Need to stop/bypass a looping startup process

Tue Jan 07, 2014 4:09 pm

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.

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Need to stop/bypass a looping startup process

Tue Jan 07, 2014 4:50 pm

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!
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Need to stop/bypass a looping startup process

Tue Jan 07, 2014 4:53 pm

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.
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Need to stop/bypass a looping startup process

Tue Jan 07, 2014 5:57 pm

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?
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Need to stop/bypass a looping startup process

Tue Jan 07, 2014 6:56 pm

Ok, never mind, have copied off of it the files I need, and so am reformatting the SD card, and setting it up again.
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

User avatar
jojopi
Posts: 3190
Joined: Tue Oct 11, 2011 8:38 pm

Re: Need to stop/bypass a looping startup process

Tue Jan 07, 2014 6:59 pm

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.

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: Need to stop/bypass a looping startup process

Wed Jan 08, 2014 7:03 pm

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.
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

Return to “Troubleshooting”