Start a command at BeagleBone boot time

9,251 views
Skip to first unread message

nuno

unread,
Apr 9, 2012, 10:37:33 PM4/9/12
to beagl...@googlegroups.com
Folks, 
I can't seem to figure out this. I have a pre-compiled C program that I use to run some simulations. I would like to run that command whenever the BeagleBone (linux) boots.
I've done this a million times on ubuntu but for some odd reason I am having a hell of a time getting it to run on my board.

My normal approach is:
1) to go to the /etc/init.d directory and create a text file in there (e.g myScript.sh)
2) edit the script to something like
#!/bin/bash
/home/root/myProgram &
3) leave the script and add execution rights to it (e.g. chmod u=+rwx myScript.sh)
4) go to /etc/rc5.d and add a symbolic link to my script in there
ln -s ../init.d/myScript.sh S99myScript

This just doesn't seem to work. Any ideas?
Also, how do I know what is the current runlevel since there is no inittab on the angstrom distribution.

Thank you all for your help!

Jacek Radzikowski

unread,
Apr 9, 2012, 10:43:13 PM4/9/12
to beagl...@googlegroups.com
Angstrom doesn't use SysV-style startup scripts anymore. It has been
replaced with systemd. You need to create service descriptor for your
program. Here is a short tutorial how to create such descriptor on F16
(should also work on angstrom):
http://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/

j.

> -- To join: http://beagleboard.org/discuss
> To unsubscribe from this group, send email to:
> beagleboard...@googlegroups.com
> Frequently asked questions: http://beagleboard.org/faq

--
Given a choice between two theories, take the one which is funnier

nuno

unread,
Apr 10, 2012, 10:15:25 PM4/10/12
to beagl...@googlegroups.com
Thanks a ton!!! I was able to get it to work. I posted a little tutorial here:
I would have linked your name / website as a reference, but since I only had your screen name... I referenced that.
Once again, thank you.

On Monday, April 9, 2012 10:43:13 PM UTC-4, Piranha wrote:
Angstrom doesn't use SysV-style startup scripts anymore. It has been
replaced with systemd.  You need to create service descriptor for your
program. Here is a short tutorial how to create such descriptor on F16
(should also work on angstrom):
http://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/

j.


On Mon, Apr 9, 2012 at 22:37, nuno  wrote:
> Folks,
> I can't seem to figure out this. I have a pre-compiled C program that I use
> to run some simulations. I would like to run that command whenever the
> BeagleBone (linux) boots.
> I've done this a million times on ubuntu but for some odd reason I am having
> a hell of a time getting it to run on my board.
>
> My normal approach is:
> 1) to go to the /etc/init.d directory and create a text file in there (e.g
> myScript.sh)
> 2) edit the script to something like
> #!/bin/bash
> /home/root/myProgram &
> 3) leave the script and add execution rights to it (e.g. chmod u=+rwx
> myScript.sh)
> 4) go to /etc/rc5.d and add a symbolic link to my script in there
> ln -s ../init.d/myScript.sh S99myScript
>
> This just doesn't seem to work. Any ideas?
> Also, how do I know what is the current runlevel since there is no inittab
> on the angstrom distribution.
>
> Thank you all for your help!
>
> -- To join: http://beagleboard.org/discuss
> To unsubscribe from this group, send email to:


> Frequently asked questions: http://beagleboard.org/faq

Gregg Harrington

unread,
Jun 13, 2012, 1:56:00 AM6/13/12
to beagl...@googlegroups.com
I have tried these steps and I couldn't get it to work from either article.

My /lib/systemd/multicomm.service file is as follows:

[Unit]
Description=Run the LED pattern script
After=syslog.target network.target

[Service]
Type=simple
ExecStart=/home/root/multicomm/run.sh

[Install]
WantedBy=multi-user.target

I chmod'ed the script to 755 to make sure everyone could run it

the script as it's first thing just creates a file via echo and them tries to launch two python programs.

#!/bin/bash
echo hi > testing.txt

cd /home/root/multicomm
/home/root/multicomm/set_pin_mux.sh
/usr/bin/python /home/root/multicomm/read_ttyO1.py &
/usr/bin/python /home/root/multicomm/read_ttyO2.py &

The script it work great when run directly from the command line.

The systemctl start multicomm.service doesn't complain when I run it. I can even enable it and disable it. But it never works unless I run it directly. Any thoughts?

Gregg Harrington

unread,
Jun 13, 2012, 2:01:05 AM6/13/12
to beagl...@googlegroups.com
Additionally when I run the command systemctl status multicomm.service it shows me this:

multicomm.service - Run the LED pattern script
          Loaded: loaded (/etc/systemd/system/multicomm.service; enabled)
          Active: inactive (dead) since Sat, 01 Jan 2000 00:27:49 +0000; 12 years and 5 months ago
         Process: 95 ExecStart=/home/root/multicomm/run.sh (code=exited, status=0/SUCCESS)
          CGroup: name=systemd:/system/multicomm.service

Jan 01 00:27:48 beaglebone run.sh[95]: name: uart1_rxd.uart1_rxd (0x44e10980/0x980 = 0x0020), b NA, t NA
Jan 01 00:27:48 beaglebone run.sh[95]: mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE0
Jan 01 00:27:48 beaglebone run.sh[95]: signals: uart1_rxd | mmc1_sdwp | d_can1_tx | i2c1_sda | NA | pr1_uart0_rxd_mux1 | N...pio0_14
Jan 01 00:27:48 beaglebone run.sh[95]: name: uart1_txd.uart1_txd (0x44e10984/0x984 = 0x0000), b NA, t NA
Jan 01 00:27:48 beaglebone run.sh[95]: mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE0
Jan 01 00:27:48 beaglebone run.sh[95]: signals: uart1_txd | mmc2_sdwp | d_can1_rx | i2c1_scl | NA | pr1_uart0_txd_mux1 | N...pio0_15
Jan 01 00:27:48 beaglebone run.sh[95]: name: spi0_d0.uart2_txd (0x44e10954/0x954 = 0x0001), b NA, t NA
Jan 01 00:27:48 beaglebone run.sh[95]: mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE1
Jan 01 00:27:48 beaglebone run.sh[95]: signals: spi0_d0 | uart2_txd | i2c2_scl | NA | NA | NA | NA | gpio0_3

Which is the correct output given the script running, yet still nothing. No scripts running, no file appearing. Nada.

Wireless Engineer

unread,
Jul 18, 2012, 10:20:09 AM7/18/12
to beagl...@googlegroups.com
Hello,

 have you tried removing the  ampersand from you shell script?

It's weird in the shell script, I had a similar problem and it didn't work for me until I provided a dump file: which is in your case could be:
/usr/bin/python /home/root/multicomm/read_ttyO1.py > /home/root/pythonlog.log



Please try this as well: 

[Service]
Type=simple
ExecStart= /usr/bin/python /home/root/multicomm/read_ttyO1.py  
-------------

k...@kenfischer.com

unread,
Jun 17, 2013, 7:13:33 PM6/17/13
to beagl...@googlegroups.com


Thanks for the explanations, and the examples.  I get to the same point as the last person who responded with issues.  If I run the shell script from the command line, it works fine.  If I start it via the systemd service, I can see evidence that it runs, because I re-direct the output of the shell script to a log file, and the file gets created, but there are no contents to the file, as if the process is hung.  There is additional evidence of the process hanging because if I run "ps -e | grep python", there is one process that is running, but I cannot tell what state the process is in.  The python program I execute from the shell script is supposed to spawn 4 other processes, each running a python program.  That never happens, at least not when systemd runs the shell script that is pointed to by the new service I created.  If I comment out the python program, and just have the shell script echo something to the console, it executes fine, and the output shows up in what the last poster refers to as a dump-file.

I have fully specified all files in the shell commands, so I know it finds them, but now I am wondering if there is something about my python execution environment that works based on my login variables, but will not work via the systemd service?  For example, when one puts in "import time", is it possible that python finds that set of libraries based on environment parameters in my login that are not there for systemd?  Maybe python is hanging looking for shared libraries?

Ken

k...@kenfischer.com

unread,
Jun 18, 2013, 8:38:30 PM6/18/13
to beagl...@googlegroups.com, k...@kenfischer.com
Not sure if anyone is looking at this old thread any more, but I think I found the problem, though I have not found a solution.  I was able to successfully define a service that starts a python program on reboot when the python program is a simple program that does not try to spawn sub-processes.  So, its not a path problem in that my "simple" program uses python modules like PySerial, PyBBIO, time, system, and all works well.  When, however, I try to start up the python process that I really want to run, which is one that uses the python library "subprocess" and tried to spawn multiple processes using the subprocess.Popen() method, the service seems to hang.  I don't know if there is some limit on which kind of process can spawn sub-processes, and whether thats allowed in systemd services or not.  Based on some other posts I found, I change the Type indicator in the service to "Type=forking", but that does not seem to have changed anything.

Ken

dhruvil...@gmail.com

unread,
Mar 24, 2017, 6:35:12 AM3/24/17
to BeagleBoard
Can you please send me the link of your video ?
I visited the link you provided in description but it could not be found.

Thanks
Dhruvil Koshti


> Frequently asked questions: http://beagleboard.org/faq

Reply all
Reply to author
Forward
0 new messages