Project

General

Profile

Linux startup with app running after boot

Added by Steven Hill over 10 years ago

I am at the final stage in getting my project working on the MityDSP L138 board. I want to load the FPGA control module and the DSPLink module and then start my application, which is designed to run until the sun goes nova or the battery runs out, whichever comes first. I have some questions:
1. Do I need to automatically log in as root and if so, how do I do it?
2. I'm having trouble figuring out the linux startup - I see /etc/init.d and the various /etc/rcx.d folders, but I can't find /etc/inittab so I assume there must be some other startup process happening - Ubuntu uses upstart, but I don't see the files necessary for that either...
3. When I type 'runlevel' I get '1' back - does that make sense?
4. Can you point me to an example of a script that will load the modules and start an application that has an argument (like HelloWorld HelloWorldDSP.out) and then exit with the application running?
5. My application produces some output that normally goes to the console. I would like to see that output while the app runs - I understand that I won't have serial input to control things but will I get the output? Is there a way to get it?

Thanks in advance for any help...


Replies (8)

RE: Linux startup with app running after boot - Added by Tim Iskander over 10 years ago

Steven

1 - No you don't need to log in as root... the init system will run your script for you. One thing that may catch you (it got me) is that HOME will not be defined when your script is run by init.
2 - Copy a simple script in /etc/init.d and tweak it to run your app. You then run "update-rc.d <scriptname> defaults" to create all the links in the /etc/rcX.d dirs. You may want/need to tweak the # assigned to your script if order is important. (If you just want your app to run after the system is "up" then the defaults should be fine.
3 - runlevel 1 is probably correct. I don't have an L138 in front of me to check, but step 2 should take care of any runlevel dependencies anyway.
4 - http://support.criticallink.com/redmine/boards/10/topics/3331?r=3339#message-3339
5 - If you start your app in init and just let it print to normal stdout, you should see it in the console. Alternatively you can redirect output to a log file or network console or something. If you use log files tho, you will have to manage them so you don't fill the filesystem.

cheers
/Tim

RE: Linux startup with app running after boot - Added by Tim Iskander over 10 years ago

Steven
One other note..
If you are using a newer filesystem with systemd (does /etc/systemd exist) things are a bit different. The link in step 4 talks about it a bit.
cheers
/Tim

RE: Linux startup with app running after boot - Added by Steven Hill over 10 years ago

I have what might seem like a dumb question. I like the idea of starting the app as a service, and I have written and tested a service that loads the fpga_ctrl and DSPLink modules on startup. My application and the files it needs to run are in a user filesystem at /mnt/user_nand. How do I get the system to switch to that directory before starting the service? I have tried running the application as "/mnt/user_nand/myApp /mnt/user_nand/mydspExecutable" but that seems to hang the system up - I don't think it likes the path to the DSP executable. So I need to switch to that directory so I can run the service with "ExecStart=myApp myDSPExecutable"

RE: Linux startup with app running after boot - Added by Tim Iskander over 10 years ago

Steven
In your script that runs the app, just "cd" to the correct directory. I.e.
cd /mnt/user_nand
./myApp mydspExecutable &

cheers
/Tim

RE: Linux startup with app running after boot - Added by Steven Hill over 10 years ago

Thanks for that, but how do you do the same thing with a systemd service? My filesystem is using systemd for startup.

RE: Linux startup with app running after boot - Added by Steven Hill over 10 years ago

I was wrong about starting the app with the full pathnames for both the app and the DSP executable. I wrote a service to start it up that way, and it works, but it crashes the terminal program (I am using Putty) and I have to restart my windows machine to get Putty running again. When I do that and check the status of the service I find that it is running. The problem is that I would like to see the printf output of the application that I normally see when I run the application from the command prompt after logging in. I'm not sure how to do this - I think that when the app is run as a service on startup that its serial output conflicts with the serial output that is coming from the system and that's why Putty crashes. Any idea on how to get the serial output working properly?

RE: Linux startup with app running after boot - Added by Jonathan Cormier over 10 years ago

You should be using normal stdout printf's in your program and not opening the serial port.

RE: Linux startup with app running after boot - Added by Bob Duke over 10 years ago

Steven,

Once you have your program output going to stdout, you can redirect it to a file that can be viewed after the system boots:

./myApp myDSPExecutable > output.dat &

If you want to watch the output of the file "live" you can try:

# tail -f output.dat
    (1-8/8)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)