How to Make an executable Linux Binary run at startup in Yocto Linux on Intel Galileo

6.2k Views Asked by At

I am trying to Implement LWM2M Client (eclipse/wakaama · GitHub) on Intel Galelio Board. I have implemented a feature where in my client ( Galileo board) will restart once executed to restart from server, but on restart my client should automatically restart which is a executable binary. I tried all option available on various forums but didn't work. I gave proper permission, updated rc.d and also it is visible in run level 3, but my binary does not get executed. Can any one please help me with this?

I have tried all the steps in this link

2

There are 2 best solutions below

0
On

Using Systemd.Service i could fix this issue.

Basically you make 'services' (text files that specify the program(s) you want to run) and put them in the '/lib/systemd/system/' folder

then you run 'systemctl enable myservice' to enable the service at bootime, there are all sorts of parameters to restart the service if the process dies, or start the service before or after network interfaces are brought up.

Add a new service script to /lib/systemd/system - have a look at the scripts there alread, a good example is the iotkit-agent.service script. So you then have yourscript.service file. To start, first refresh systemd, then try to start your new service systemctl daemon-reload systemcrl start yourscript.service

You can then use 'systemctl status yourscript.service' to see if it's started and alive.

If you want it to start at boot, you have to 'enable' it systemcrl enable yourscript.service
which creates a softlink to your script from the relevant directory in /etc/systemd/system/... Now reboot and see if it comes up ok.

If your script calls a binary that needs environment vars set up, be sure to include them in the script, LD_LIBRARY_PATH is a common var needed: LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib export LD_LIBRARY_PATH

You can check this link for complete discussion & information

0
On

It's had to tell from a distance. Some ideas to get it working:

  1. You shouldn't link your executable directly; files in /etc/init.d should be scripts which invoke the executable with the correct options.

  2. After installing the script, try to run it from the command line to make sure it works.

  3. Select a number between two scripts which run in your runlevel. So if you have scripts with numbers 10 and 20, give your script 15. If you see the 20 script run during boot, you can be pretty sure that your script was run before that.

  4. Add logging to your script to check whether it fails at some point. A simple

     echo "1" >> /tmp/l2m.log
    

    is enough to see how far your script gets.

  5. Add -x to the hashbang line of the start script to make it print every command before it executes it.

  6. Make sure the output of your executable is redirected properly, so you can actually see any errors.