Rilhas
Posts: 36
Joined: Sat Aug 04, 2012 7:52 am

Running applications on startup

Sun Aug 05, 2012 4:54 pm

Hi,

I'm having trouble running applications on Wheezy startup. I've tried a lot of things, so my system may be somewhat messed up by now, but I would like to try anything you care to suggest before reformatting the whole thing and starting over.

My applications are started from an "autoexec.sh" script. So, what I want to do is call this script at boot time, as late as possible into the boot process to make sure everything else in the system is ready. For now the "autoexec.sh" script calls all the applications with sudo.

First I've tried rc.local, adding something like "touch file1", "sudo /bin/bash /app_path/autoexec.sh ", "touch file2", and then adding a link to rcS.d. This didn't work, and adding a link to rc2.d seemed to work but it didn't really as both files 1 and 2 appeared but my applications didn't run.

So I reverted all of that (I think) and tried "sudo update-rc.d start_my_stuff.sh defaults". The idea was the same, I created the "start_my_stuff.sh" in init.d with "touch file1", "sudo /bin/bash /app_path/autoexec.sh ", "touch file2". This still didn't work, but the result was not exactly the same as before. The 2 files were created, but this time my applications did in fact run (one of them sends an e-mail on startup and I received that e-mail), the problem is that they run only for a short while and then get killed somehow.

So, by the time I login through SSH and check for running processes my applications are not there, but checking their logs I see that they started. The logs also show an abrupt unexpected termination, but checking dmesg didn't yield any information about processes segfaulting or being killed.

Invoking "sudo ./autoexec.sh" from a terminal window (through SSH) works and all applications are started and keep running even after I logout, so there is nothing wrong with the script. Invoking the “start_my_stuff.sh” script in init.d from the terminal also starts everything correctly, so all the scripts are good.

Any ideas why my applications are being killed? Or, alternatively, is there any better way to run my script on startup that actually works? I have little faith that starting over will solve anything, but I ran out of ideas.

Thanks!

alexchamberlain
Posts: 121
Joined: Thu Jun 14, 2012 11:20 am
Location: Leamington Spa, UK
Contact: Website

Re: Running applications on startup

Sun Aug 05, 2012 4:58 pm

I'm no great expert on this, but I'm pretty sure rc.local will be run as root - get rid of `sudo`.
Developer of piimg, a utility for working with RPi images.

JeremyF
Posts: 515
Joined: Wed Jan 25, 2012 9:06 pm
Contact: Website

Re: Running applications on startup

Sun Aug 05, 2012 5:20 pm

You could also alternatively put the script in the folder /etc/init.d , although this may not work as not all other services will have started yet. You could also turn on auto login and put the command in /etc/profile . (/etc/profile instructions here http://elinux.org/RPi_Debian_Auto_Login, change "startx'' to the script)
{sig} Setup: Original version Raspberry Pi (B, rev1, 256MB), Dell 2001FP monitor (1600x1200), 8GB Class 4 SD Card with Raspbian and XBMC, DD-WRT wireless bridge

flightvision
Posts: 21
Joined: Sat Apr 21, 2012 9:04 am

Re: Running applications on startup

Sun Aug 05, 2012 8:00 pm

/etc/rc.local is called during startup (I have my network setup with some setting of routes there) and yes, it works in Raspbian (gets called before the first login console is available, not sure in which runlevel but network is avail).

your second solution will also work:
1) script in /etc/init.d/$SCRIPT (see /etc/init.d/skeleton if you want to do it really right)
2) don't forget chmod +x
3) it will be called with `/etc/init.d/$SCRIPT start` and `/etc/init.d/$SCRIPT stop`, so check if it does what it should in these cases. Do `exit 0` if it was successful.
4) `update-rc.d $SCRIPT defaults` - you are now officially a SysV-initscript.
5) `find /etc/rc?.d | grep $SCRIPT` will show you in which runlevels you will be called.

User avatar
joan
Posts: 15271
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Running applications on startup

Sun Aug 05, 2012 8:11 pm

I dislike mucking about with start up scripts. I'd just bung in a cron job to be run at boot, e.g.
# m h dom mon dow command
@reboot /home/common/bin/reboot-jobs
*/15 * * * * /home/common/bin/get-router-stats
*/15 * * * * /home/common/bin/check-sites
man 5 crontab

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Running applications on startup

Sun Aug 05, 2012 8:22 pm

I always use a startup script in etc/init.d, I find it the most reliable and robust because it starts up and shutdowns automatically.

For an example and instructions see this blogpost.

http://stuffaboutcode.blogspot.co.uk/20 ... rt-up.html

LHIS
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

Rilhas
Posts: 36
Joined: Sat Aug 04, 2012 7:52 am

Re: Running applications on startup

Sun Aug 05, 2012 9:00 pm

alexchamberlain wrote:I'm no great expert on this, but I'm pretty sure rc.local will be run as root - get rid of `sudo`.
Thanks for you suggestion. I initially tried it without the sudo, and it didn't work, and although I didn't know the reason why I inserted the sudo's in the script just to be on the safe side. I retried it again without sudo's and it still sort of doesn't work, in the sense that the applications are started but are then killed right away. Reading their logs gives me the impression that each application runs for less than a second. In fact, two applications have logs detailed enough to see that they run for aproximately 50 ms (yes, read milliseconds).

Meanwhile I've added user "pi" to the "root" group, so maybe that is why I don't need to sudo the scripts anymore. I'm kinda lost by now, just shooting in all directions to see if I get a hit. :)

Any other ideas?

Rilhas
Posts: 36
Joined: Sat Aug 04, 2012 7:52 am

Re: Running applications on startup

Sun Aug 05, 2012 9:21 pm

JeremyF wrote:You could also alternatively put the script in the folder /etc/init.d , although this may not work as not all other services will have started yet.
Nice! I don't know why I didn't think of that and immediately went for the script-running-a-script option.

Unfortunately however, it doesn't work. This time the applications aren't even started, and the "pre and post touch files" are not even created. If I open a terminal after boot and directly call the script from /etc/init.d it works, so I don't know why this is not working.
JeremyF wrote:You could also turn on auto login and put the command in /etc/profile . (/etc/profile instructions here http://elinux.org/RPi_Debian_Auto_Login, change "startx'' to the script)
In my various attempts I did run into this post, but I think it may be a little bit out of my league. Here's why: when installing the SD card for the first time I selected the desktop to start automatically (don't remember the exact wording of the option). That worked, and my Pi boots onto the desktop (X server LXDE, right?). But then, looking at my /etc/profile, there is no call to "startx". So, if I'm already starting X and that is not being done by the /etc/profile I was worried that if I followed the steps in the post I would probably endup with conflicting boot configurations, so I didn't do it. Should I try it anyway?

Anyway, your suggestion inspired me to try to add a call at the end of the /etc/profile to call my script and it didn’t work, not even the “touch files” appeared.

Any other ideas?

Rilhas
Posts: 36
Joined: Sat Aug 04, 2012 7:52 am

Re: Running applications on startup

Sun Aug 05, 2012 9:38 pm

flightvision wrote:/etc/rc.local is called during startup (I have my network setup with some setting of routes there) and yes, it works in Raspbian (gets called before the first login console is available, not sure in which runlevel but network is avail).
Maybe I should mention that my applications reside in an USB disk, so I also need this disk to already be mounted. That is why I wanted my script to run late, really late into the boot process.
your second solution will also work:
1) script in /etc/init.d/$SCRIPT (see /etc/init.d/skeleton if you want to do it really right)
2) don't forget chmod +x
I thought so, but the applications run for only 50ms. So the "start running" part of the problem is solved, the "keep running" part is what I need to solve.

That "skeleton" thing got me a little scared... I turned on all the lights in the room but I'm still a little frightned by that. Do I have to do all of that???

The "chmod" I did right, calling the script manually works.
3) it will be called with `/etc/init.d/$SCRIPT start` and `/etc/init.d/$SCRIPT stop`, so check if it does what it should in these cases. Do `exit 0` if it was successful.
This made me think that maybe I haven’t been doing it right. I just put a simple linear script in /etc/init.d calling my stuff, and my stuff didn’t get called. Thenm when I did the “update-rc.d” thing, it did run but only for 50ms. Do you think I have to do those “case start” and “case stop” things in my script? Just calling my applications in sequence is not enough? Could this explain my applications running for only 50ms and then being shot down?

Rilhas
Posts: 36
Joined: Sat Aug 04, 2012 7:52 am

Re: Running applications on startup

Sun Aug 05, 2012 9:43 pm

joan wrote:I dislike mucking about with start up scripts. I'd just bung in a cron job to be run at boot, e.g.
I think I'm ready to join you. And maybe even form a club or start a cult. :)

I've heard of that cron thing before, I'll look it up. Thanks!

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Running applications on startup

Sun Aug 05, 2012 11:21 pm

This made me think that maybe I haven’t been doing it right. I just put a simple linear script in /etc/init.d calling my stuff, and my stuff didn’t get called. Thenm when I did the “update-rc.d” thing, it did run but only for 50ms. Do you think I have to do those “case start” and “case stop” things in my script? Just calling my applications in sequence is not enough? Could this explain my applications running for only 50ms and then being shot down?
When the script is called at boot it will call "/etc/init.d/YourScript start" then at shutdown "/etc/init.d/YourScript stop" if you do nothing with the parameters then I don't think it will matter, but you might find your script executing again at shutdown which might not be what you want.... So I would say yes, you need to use a case statement to do different things when start is passed and when stop is passed.
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

Rilhas
Posts: 36
Joined: Sat Aug 04, 2012 7:52 am

Re: Running applications on startup

Sun Aug 05, 2012 11:52 pm

I finally got it. Well, I didn't really get it, but I was finally able to work around it.

Being just about ready to give up I tried setting up a cron job at boot time, and it didn't work. I thought to myself that that was a little bit too much, enough was enough, so I tried starting a job, at boot time, that just created some file somewhere.

Actually not "somewhere", fortunately I chose to create a file in "/Temp" instead of "/media/USBApplicationsDisk/Temp" because it was shorter, and it worked: the file was created. So it started to make sense that "late in the boot process" for rc.local and init.d and update-rc.d and profile and all those variants was not late enough for the USB disk that contains the applications to become ready.

So I tried sleeping for 30 seconds at the start of my original script, and moving it to the "/Temp". The cron job at boot time started it, and 30 seconds later my applications started to run!! …and they kept on running!! Great!!!

The final solution was to have my script start with a loop where it tries to create a file in the USB disk and if unsuccessful then sleep for 1 second and then retry. If successful just move forward and start the applications.

The weird part left to work out is why the applications ran for 50 ms when started while the USB disk was not ready and then died. One might think that maybe the USB disk is mounted in several steps, going back and forward between available and unavailable, but my application’s startup sequence is something like “launch app 1”, “sleep 2 seconds”, launch app 2”, “sleep 2 seconds”, … and so it is hard to understand how the disk becoming available and unavailable in rapid succession caused each application to execute for 50ms. It seems easier to believe that the script would fail to launch the applications most of the times, but it executed all applications for a fraction of the second everytime. Plus, the new script that loops until it is able to create a file seems to work consistently.

So I don’t know why it was acting up, but now that it is working I just want to make 20 backups, burn them on 20 DVD’s, mail them to 15 distant friends and 5 bank deposit boxes for safe-keeping, never touch it again, and never look back.

Thanks to all for your help!

puddle247
Posts: 10
Joined: Tue Jun 12, 2012 7:03 am
Location: Near Newark, Notts

Re: Running applications on startup

Wed Aug 08, 2012 6:08 am

Gobbledygook, run - an unknown command; frustration - a game of never ending loops beginning with linux, going through debian and squeezed wheezily through a rasberry.
I'm having a rant!!!
I got my pi in June and my desk is littered with breadboards, resistors, trannies, leds and connecting wires that have no place to go. I started to try and get a led ladder working and found to my horror that two libraries called GPIO existed in my poor new pi. So my ladder wouldn't work without installing wiringpi, which also has a version of GPIO.
I have oodles of time on my hands being retired and 'old' and so decided to put my family tree progam on my pi. Genopro tell me that it has a linux version that runs with 'wine' Downloaded wine-unstable 1.5.5-0.1. and all the files necessary for Genopro. Can't find a command to configure wine! Can't find a list of command codes at all. No wonder Linux is a mystery - seems to me to be a missed-story. Lots of techies use it but keep it to themselves, I think - and that is called 'open-source'. Please help - I want to know where to find a dictionary or Theasurus of Linux commands and structures that work on my RPi.

itimpi
Posts: 1090
Joined: Sun Sep 25, 2011 11:44 am
Location: Potters Bar, United Kingdom
Contact: Website

Re: Running applications on startup

Wed Aug 08, 2012 7:03 am

Note that wine will not run on the Pi. It only runs on Linux systems using an Intel processor, whereas the Pi has an ARM processor.

puddle247
Posts: 10
Joined: Tue Jun 12, 2012 7:03 am
Location: Near Newark, Notts

Re: Running applications on startup

Wed Aug 08, 2012 7:15 am

itimpi wrote:Note that wine will not run on the Pi. It only runs on Linux systems using an Intel processor, whereas the Pi has an ARM processor.
Gee thanks. Frustration will not disappear. Still need to know what command = run

alexchamberlain
Posts: 121
Joined: Thu Jun 14, 2012 11:20 am
Location: Leamington Spa, UK
Contact: Website

Re: Running applications on startup

Wed Aug 08, 2012 7:28 am

The problem is that a list of all Linux commands would always be incomplete and pretty useless.

You need to learn by doing. Follow some tutorials, either on the wiki, at Raspberry Pi.SE or by Googling. Then ask if you can't do what you want. Use man pages and experiment.
Developer of piimg, a utility for working with RPi images.

Rilhas
Posts: 36
Joined: Sat Aug 04, 2012 7:52 am

Re: Running applications on startup

Wed Aug 08, 2012 11:24 am

puddle247 wrote:No wonder Linux is a mystery - seems to me to be a missed-story. Lots of techies use it but keep it to themselves, I think - and that is called 'open-source'. Please help - I want to know where to find a dictionary or Theasurus of Linux commands and structures that work on my RPi.
Like you I feel the frustration of being an outsider to Linux. This frustration is only exacerbated sometimes when "Linux Wizards" don't really explain you stuff. For example, trying to solve the problem I described on this post I ran into several posts saying "only activate the root account if you know exactly what you are doing". Does anyone really know exactly what they are doing with Linux? Is there a scale to measure how exact is one’s knowledge of Linux? And is there a threshold beyond which one can claim to know exactly what one is doing? And am I past that threshold if I already know not to do “sudo rm –rf *”? And what will be the consequences of activating the root account if I don’t know exactly what I'm doing? Will it die the next time I type “ls” on the terminal or will some intercontinental missiles accidentally fire away from my Pi and start WW3 and destroy the world if I type the wrong command? It is really frustrating to try to learn through these obscure advices which endup not being helpful at all.

Anyway, I've been dealing with Linux for about 2 years now. I'm a Windows guy, not because I like Windows but because - really - I don't want to learn about an OS and I just want to use it. My frustration is then augmented some more because "Linux Wizards" typically think that you are an idiot by not wanting to know Linux in depth (because they usually think *everyone* should have in-depth knowledge of this wonderful thing to which they dedicated their lives). Any less than that and they usually shut you out. And they have no problem letting you know that "if you don't want to know Linux exhaustively then you should stick to Windows".

The solution? Similarly to what alexchamberlain advised, I did learn it by doing. Well, I didn’t really learn it, I learned a little bit. I made peace with the fact that you do need to learn a little bit of it, and I did learn that not everything is simple and straightforward with Linux. In doing that you spend time - true - and for me that time spent feels most often close to a waste of time, but I do end up getting things to work. And, after some time, I do feel that the “Linux surprise factor” (the probability of something in Linux taking me by surprise and not working as expected) is getting smaller and smaller.

For example, to solve the problem in this post I spent about 10 hours. After that I did come to a conclusion, and solved the problem. If I had known from the start what the problem was, or if anyone had told me, or if I found a similar situation on forums, I could have solved it in 3 minutes, so I felt like I had wasted 9h57m of my life without necessity. But that is not strictly true, because in those 9h57m I did learn about “rc.local”, “init.d”, “rcS.d”, “rc2.d”, “update-rc.d”, “cron”, “crontab”, and many other mysterious magic formulas and potions. More importantly, I learned that there are many variations on how different flavours of Linux startup things (hence the “update-rc.d on Debian), so - and trying to remain as OS-agnostic as possible - I decided (by myself and against the Wizard’s advice) that, in the future, I will start everything with “cron @reboot” instead of messing with init files. So, all in all, I did learn a lot in those 9h57m, and although I would have rather have been doing something else with that time, I must admit it was not a waste.

So I would complement the advice with the following: first take the time to know what your system is. This is *VERY* important when you are googling for solutions to problems or for how to do things. And usually the Wizards do not tell you this, they assume you already know because otherwise “you should stick to Windows”. Here is a list (possibly incomplete) of things you should know about your system:

a) What processor does your machine have? For the Pi it is an ARM processor, for a desktop it is usually an Intel x86. Compiling things for a specific processor by yourself requires a whole other level of knowledge and expertise, so if you don’t find things already built for your processor then you are in trouble. The easiest way to get things that work for your processor is using “apt-get”, but precompiled binaries also usually work well. If you find none of these for the processor you want then I recommend you forget about it and try some other thing. Note that even if some post says that it is as simple as make-file-this and gcc-that it is probably not true, otherwise you would likely be able to find binaries or apt-get would work.

b) What distribution and version of Linux are you using? Googling “how to determine linux version and distribution” tells how to determine this. For me it is “Debian GNU/Linux wheezy”. Never ever ever forget this when you are googling and reading posts, because otherwise you may easily endup following wrong advices from posts and mess up your system.

Then you can follow a set of procedures to help you. When googling always try to be specific. This is a general advice, but for Linux it is almost a requirement because Linux is a never ending world of variations and particularities. So if you want to know how to enable “xpto” then don’t just search for “linux xpto”, type “how to enable xpto wheezy”. Common subjects may have a lot of pointless posts, and being specific helps save you time.

One thing I started to realize is that it is best to work heavily on the search string rather than work hard reading a lot of posts. Google does a good job of interpreting your search, so type something, skim through the first 10 results, and if you don’t feel like you are going to find the answer there then refine your search and try again. This method works best if you configure Google to open results in new pages (so that you can easily try a result and close it with CTRL+W if it does not satisfy you). Also, don’t upgrade to “modern browsers that think that it is clever to eliminate the search box and allow searching through the address bar”. I’m refusing to upgrade my Internet Explorer 8 to 9 just because of that, with IE8 I can simply press CTRL+E to go to the Google search box and refine my previous search, browsers that search from the address bar typically forget the previous search and you have to start from scratch every time. Of course you can click on Google’s web page in the box where your query is shown, but using the mouse while refining searches easily triples the time it takes me to get a useful result.

But this is not all. If what I want is not obvious immediately after opening a search result I press CTRL+F to find on the page, and then type a key word. If I’m looking for how to enable xpto I would probably type “enabl” (to find “enable” and “enabling”) and then the browser highlights the parts that may interest me the most. In this example I didn’t type “xpto” because, presumably, the whole post is about “xpto” if google did its job right, so I would find it everywhere in there.

Another advice (mostly a summary of the above) is that you should try to find first what things are and if they are applicable to your case. For example, Googling “wine arm” is a good way to know if it is applicable to the Pi. The first post says no (at least judging by what I think you want to do with Wine), but if it had said yes I would then Google “wine wheezy”, and if that didn’t work I would search for “wine debian”.

With these techniques it now takes me very little time to get things done in Linux, and I was able to configure my Pi (and other tiny computers I used before it) to do what I want: http://www.rilhas.com/RaspberryPi/RaspberryPi.html

I hope this helps!

User avatar
M.M
Posts: 107
Joined: Fri Aug 03, 2012 7:40 am
Location: Hamburg, GER

Re: Running applications on startup

Wed Aug 08, 2012 12:03 pm

Hello folks,

though I can understand the frustration in having to deal with things that appear incomprehensible at first, I think that especially here in the RPi forums (and even more in the "New Linux user help" section) there are plenty of people willing to help with the average Linux newcomer in mind.

But of course, most of the time answers will be more like "read up on that topic here" or "did you try to do this" instead of "type xyz in the terminal. done." because that way you get a deeper insight into what's going on. That's how "techies" in the open source field tend to think.
I'm a Windows guy, not because I like Windows but because - really - I don't want to learn about an OS and I just want to use it
Why do you complain about being an outsider then? I am an outsider in rocket science. Because I don't know enough about it and do not have the time or the will to change that.

We are pretty far along the way with distributions like Ubuntu that "just work". But often something does not. Why? Well, mostly because of some proprietary B$. For example most hardware vendors don't bother with Linux compatible drivers. Therefore the hardware does not work with Linux out-of-the-box. Why don't they bother? Because there is not enough Linux customers generating market share. And why is that? Because people try Linux, recognize that it's not as "fool-proof" as Windows and say "f' that s', I'm going back to Windows.". So the number of Linux users does not grow significantly -> no market share -> no drivers -> frustration. You see the vicious cycle?

It seems like people feel "victimized" by open source when really they are part of the problem.

Just my two cents...

On the topic of command overviews for Linux: I got myself O'Reilly's "Linux in a nutshell" in the beginning of my Linux journey. Costs about 10 bucks and I liked it.

On the topic of the thread: As you seekm to have found out by yourself

Code: Select all

update-rc.d <name> defaults
automatically adds startup scripts to all runlevels for a given program.
"If people read the FAQs the Qs wouldn't be A F, would they?"

Rilhas
Posts: 36
Joined: Sat Aug 04, 2012 7:52 am

Re: Running applications on startup

Wed Aug 08, 2012 12:19 pm

M.M wrote: Why do you complain about being an outsider then? I am an outsider in rocket science. Because I don't know enough about it and do not have the time or the will to change that.
... but... do you want to use rockets? My point is that I want to to live in my house and use it without knowing how it was built. Linux has reached a point where it can work out of the box (I got that feeling when I first got my Pi and it booted to a neat desktop full of icons), but it repeatedly makes me feel like an outsider when "wizards" shut me out because I just want to learn enough to use it, not to become my next religion. I then feel an outsider just like I would if I had to enter 6 commands and edit 3 files just to be able to flush my toilet and "construction wizards" shut me out because I don't want to learn construction or even "the toilet flushing science logic of typing 6 commands end editing 3 files".

I don't blame Linux for all of this (nor the open source concept). Linux got where it got today through its own history and is own sequence of contributions throughout the years, so if I just arrived now and I want to use it of course I should be prepared for what it is, not the other way around. What I do blame is the multitude of bad, misguided, and obscure advice out there, mostly spewed out by "Linux wizards" who can create the sense of frustration I saw here, in many other places, and that I felt myself.

But I do agree: I haven't noticed any of that nasty "wizard syndrome" in this forum. :)

User avatar
M.M
Posts: 107
Joined: Fri Aug 03, 2012 7:40 am
Location: Hamburg, GER

Re: Running applications on startup

Wed Aug 08, 2012 12:28 pm

Hi Rilhas,

I would effin' LOVE to use a rocketship ;) But you are right, the comparison was a bit far fetched :D

I know that feeling of being belittled by the "know-it-alls" too well. And seeing stuff like that happen still enrages me to no end. I am glad you don't feel like that around here.

I totally get your point. Hopefully, we around here in the forums can do something about the frustration and be more like Linux buddies rather than Linux wizards :)

Regards
"If people read the FAQs the Qs wouldn't be A F, would they?"

alexchamberlain
Posts: 121
Joined: Thu Jun 14, 2012 11:20 am
Location: Leamington Spa, UK
Contact: Website

Re: Running applications on startup

Wed Aug 08, 2012 12:31 pm

The forums here are great for asking new questions. There are also the Stack Exchange (SE) sites.

Raspberry Pi.SE
An SE site dedicated to the Raspberry Pi. People here are very happy to answer very basic questions and will migrate inappropriate questions else where.

Unix & Linux
An SE site dedicated to Unix and Linux. People here tend to have a little more in depth knowledge of Linux, but your questions may get lost in a load of more advanced questions. The Raspberry Pi moderators will migrate your question here if they feel it isn't answered adequately on Raspberry Pi.SE.

Stack Overflow
This is the original SE site - commonly known as SO. It provides all kinds of programming support, but there is the odd Linux question here too.

I'm a member of all 3. Personally, I use them for questions and this forum for discussion, or where I don't get an answer there.
Developer of piimg, a utility for working with RPi images.

xavierett
Posts: 3
Joined: Mon Nov 26, 2012 1:15 pm

Re: Running applications on startup

Wed Nov 28, 2012 10:46 am

flightvision wrote:/etc/rc.local is called during startup (I have my network setup with some setting of routes there) and yes, it works in Raspbian (gets called before the first login console is available, not sure in which runlevel but network is avail).

your second solution will also work:
1) script in /etc/init.d/$SCRIPT (see /etc/init.d/skeleton if you want to do it really right)
2) don't forget chmod +x
3) it will be called with `/etc/init.d/$SCRIPT start` and `/etc/init.d/$SCRIPT stop`, so check if it does what it should in these cases. Do `exit 0` if it was successful.
4) `update-rc.d $SCRIPT defaults` - you are now officially a SysV-initscript.
5) `find /etc/rc?.d | grep $SCRIPT` will show you in which runlevels you will be called.
Hello, I've tried to start a python program before the exit 0 in /etc/rc.local
Thing I've done:
1. Change the rc.local file using# nano -w /etc/rc.local
2. Write the path of RPi.py test program (just print "Hello World") in rc.local before the exit 0
#sudo python /path/RPi.py
3. Ctrl X / Yes / Enter
4. Reboot
As I read It is just the way to auto-start an application before the to login but it doesn't works.
Could someone help me?

I'm just a beginner so I would like simple answers if it is possible.

Thanks

Sorry for my English. I'm not a native speaker.

xavierett
Posts: 3
Joined: Mon Nov 26, 2012 1:15 pm

Re: Running applications on startup

Wed Nov 28, 2012 1:04 pm

Sorry. It works perfect. It was just a mistake because I wrote the path in /etc/rc.local and the correct path is etc/init.d/rc.local.

Sorry if someone has lost a minut in this disapointing mistake.

markcamos
Posts: 9
Joined: Sun Jun 03, 2012 7:44 pm

Re: Running applications on startup

Sat Dec 15, 2012 4:26 pm

@Rilhas - Very nice advice. I wish I had read it a couple of years ago when I first started using Linux. I think the problem with wizards is that they've forgotten what they didn't used to know... and explain things from the perspective if what they know now. This isn't just a Linux problem - wizards of all sorts have this same blind spot. Most of the time, they're not trying to be obscure in their responses, they're merely trying to be efficient.

In any case, nice post!

pee
Posts: 4
Joined: Sun Jan 13, 2013 8:38 pm

Re: Running applications on startup

Sun Jan 13, 2013 9:38 pm

Hi All.

When I Google "raspberry pi startup applications" this forum thread is the first result that comes up,
and that's why I'm writing this here.

I'm a new Pi user (Raspbian Wheezy LXDE) though I'm not entirely new to Linux.
In bigger distros, like Mint 12 Cinnamon, I'm used to being able to find something on the main menu
like "Preferences / Startup Applications". Needless to say, it's not there in Raspbian Wheezy LXDE.

However, this kind of very late launch is what many people are likely looking for. Delving into the
run-level boot scripts is not only spooky, but often has you running sooner than you'd like,
for instance, when your desktop isn't even up yet.

Well, as it turns out, all a provision like "Startup Applications" does is to stuff launchers into
.config/autostart within your home folder. (Use View / Show Hidden to see dotted files and folders.)
Now, sadly, if you look in /home/pi/.config you find that there is no folder called "autostart".

But it turns out that this "autostart" folder is well supported. So guess what? If you make an
"autostart" folder inside /home/pi/.config and if you put a valid launcher in there, it works!

If you're not familiar with launchers (aka desktop configuration files) I won't presume to pontificate
on the matter, but I will tell you that it's just a little text file, and I'll show you mine as an example...

[Desktop Entry]
Name=Mouse Tamer
Type=Application
Comment=Tame the wireless mouse.
Exec=/home/pi/MouseTamer

The above five lines are in a file called FixMouse.desktop within /home/pi/.config/autostart
The target of that Exec line is a script I need to run, but it could just as easily be anything else.

So, it's not quite as easy as Main Menu / Preferences / Startup Applications
but if you don't mind creating folder autostart within /home/pi/.config
and creating a little five line text file in there with the extension "desktop", well...
it's not a whole lot harder.

Caveat: Desktop files can be much longer than five lines, and, depending what you're trying
to do, yours may need to be.

Return to “Beginners”