oilrigg
Posts: 12
Joined: Sat Nov 17, 2012 9:22 am

Raspberry PI custom script blocking at bootup

Sat Jan 26, 2013 10:22 am

I created a custom script and configured it to run at bootup. The problem is I can't seem to stop the script by using control+c. Is there a way to stop this script by entering a certain command on the keyboard?

I can't ssh into it at this point because it seems like the ssh module hasn't initialized yet. Is it possible to access my script file by loading the sd card on my mac and editing it there?

xian
Posts: 51
Joined: Thu Nov 01, 2012 8:42 pm

Re: Raspberry PI custom script blocking at bootup

Sat Jan 26, 2013 11:50 am

You need another box that can use ext3(?). Another linux box is fine, including your pi booted off a fresh image. Then attach your broken sd card and poke around to see what went wrong.

I'm guessing your using an init.d script that didn't terminate. These are not supposed to run for ever but just start stuff in the background. So if somehow the script doesn't terminate, the boot process won't continue.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Raspberry PI custom script blocking at bootup

Sat Jan 26, 2013 12:27 pm

If your script doesn't start in runlevel 1, then there is a command line option to the kernel you can use to start in that state.

Add the parameter "S" (without the quotes) to cmdline.txt

You'll get a root command-line prompt and can edit the script from there.

(cmdline.txt is, of course, in /boot, which you can see on another PC.)

oilrigg
Posts: 12
Joined: Sat Nov 17, 2012 9:22 am

Re: Raspberry PI custom script blocking at bootup

Sun Jan 27, 2013 2:30 am

Thanks for the replies. I was able to get the command-line prompt by editing the cmdline.txt file and appending the character S. I was able to edit my script and added

Code: Select all

Required-Start:    $ALL $sshd
and re-registered to update-rc.d to get my script to bootup last. I'm able to ssh into my raspberry pi, but it seems like the script isn't booting up as a background process since the login query never displays. Here's the bootup script.

Code: Select all

case "$1" in
	start)
		echo "Starting MyScript"
		sudo /home/pi/myScript $
		;;
	stop)
		echo "Stopping MyScript"

		killall myScript
		;;
	*)
		echo "Usage: /etc/init.d/MyScript {start|stop}"
		exit 1
		;;
esac
Is this the correct way of running a bootup script in the background?

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

Re: Raspberry PI custom script blocking at bootup

Sun Jan 27, 2013 2:50 am

To start a background process, use a trailing &, not a trailing $.

You do not need sudo because all boot scripts start as root. But if the process does not need to be run as root, then it is safer to run it as an unprivileged user with "su USER -c 'COMMAND' &".

oilrigg
Posts: 12
Joined: Sat Nov 17, 2012 9:22 am

Re: Raspberry PI custom script blocking at bootup

Sun Jan 27, 2013 3:27 am

Thanks! That fixed it.

The process that runs writes to a txt file located in the /home/pi directory. If the program is run using:
"su USER -c 'COMMAND' &", will it have write permission?

User avatar
rpdom
Posts: 15600
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Raspberry PI custom script blocking at bootup

Sun Jan 27, 2013 9:08 am

oilrigg wrote:The process that runs writes to a txt file located in the /home/pi directory. If the program is run using:
"su USER -c 'COMMAND' &", will it have write permission?
If you run it as "su pi -c '/home/pi/myScript' &", yes. It will be running as user "pi" and will have all the permissions associated with that user.

Return to “General discussion”