Page 1 of 1

Run Shell Script On Boot

Posted: Thu Mar 06, 2014 11:24 pm
by greenlemon
Alreet folks,

I've had a Pi for a while doing nothing but running XBMC :shock:
I recently decided to run it as an internet connected headless music server to run my music via a flash player on any PC.
I've got this working for the most part but not as headless as I wanted, I have the RPi with nothing more than an Edimax WiFi Dongle and a 1TB Ext HDD containing the music. The service I have runs perfectly well but I have to SSH into the Pi to start to run a shell script the run the .jar file to start the service. Trouble is when I ssh into my pi and start the service I get the following.

Code: Select all

pi@raspberrypi ~ $ ./startup.sh
Started admin server on port 9092
I expect this to happen when running it from a command prompt so it makes sense that it does it over SSH. Trouble is I then have a laptop with a ssh terminal open that I can't close or the service stops.

I'm trying to get the file /home/pi/startup.sh to run at bootup. I have the pi setup to boot straight into LXDE.

I must be missing something here but I can't get it to start.

I've added

Code: Select all

@reboot /home/pi/startup.sh
To the crontab file and cron is running.

I'm running an image of Raspbian I downloaded only a few days ago from this site.

Can anybody shed any light on what I might be doing wrong?

Any help much appriciated!

Re: Run Shell Script On Boot

Posted: Fri Mar 07, 2014 6:50 am
by ripat
This looks like your script needs some other services to run before being able to start. Try to capture the STDERR that your script might produce or have a look in the syslog file for more cues.

Easy fix: put a delay in that script to give some time for all services to start up (sleep(x) instruction)

More elegant solution: use the init-V hierarchy (run levels) and the init.d scripts (Init Script LSB - Linux Standards Base) to control when your service will be launched. This a more elegant solution because you can determine there when to start and stop your service and at what run level.

Example of an init.d header:

Code: Select all

### BEGIN INIT INFO
# Provides:          skeleton
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $portmap
# Should-Stop:       $portmap
# X-Start-Before:    nis
# X-Stop-After:      nis
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO
You can take any existing init.d script and start modifying it to suit your needs. More info:
/etc/init.d/README
man insserv
man update-rc.d