radiohits
Posts: 1
Joined: Mon Oct 22, 2012 11:14 am

Startup scripts

Mon Oct 22, 2012 11:18 am

Hi all,

Firstly, loving the PI...I'm just experimenting with using it to receive an RTSP stream from a webcam. I have mplayer dumping it to a named pipe, then running omxplayer to decode it.

All I now wanna do is make sure this happens on bootup, so I need to get the Pi to automatically login as a user, and then run mplayer, followed by omxplayer...

I have absolutely no skills with BASH, so just wondering if someone can help?

Thanks

Craig

User avatar
jecxjo
Posts: 158
Joined: Sat May 19, 2012 5:22 pm
Location: Minneapolis, MN (USA)

Re: Startup scripts

Wed Oct 24, 2012 6:44 am

A few things you'll want your init script to do:

Start
The startup portion of your script should start the application (in daemon mode or as a background process), store the process id into a pid file and then exist gracefully. Might be worth while to check the pid file first to see if the process is currently running.

Stop
Checking the pid file, you'll want to kill the process and then delete the file. Pretty simple.

Status
Here you check the pid file, and display if the process is running or not.

Restart
Call stop, then start.

Arguments
The last step is to catch the single argument being passed to the script: start, stop, status, restart.

So put that all together you get a pretty simple script. I'd recommend you check out some other init scripts in your system to find out the exact nature of doing things like storing pid, printing status to the screen, etc.

I'll post some code tomorrow.
xmpp: [email protected]
Blog: http://jecxjo.motd.org/code

User avatar
jecxjo
Posts: 158
Joined: Sat May 19, 2012 5:22 pm
Location: Minneapolis, MN (USA)

Re: Startup scripts

Thu Oct 25, 2012 12:25 am

Rather than reinventing the wheel...here are a few examples I found via Google:

https://github.com/fhd/init-script-template

http://werxltd.com/wp/2012/01/05/simple ... -template/

Hopefully these are pretty self explanatory. Fill in the parts you need and try it out.
xmpp: [email protected]
Blog: http://jecxjo.motd.org/code

Return to “Beginners”