I am not sure exactly what you want to do, but I suspect systemd is what you want
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.
Edit: I am not sure why my service file was auto renamed to .zip (either the forum auto zips files, or you will have to rename the file to my-service.service)
my-service.service.zip 311 bytes
1 of 1 people found this helpful
Just to add to Dan's response above...
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
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:
I tried the steps in the mentioned link but i am getting the following error
Active: activating (auto-restart) (Result: exit-code) since Fri 2015-02-27 21:18:35 PKT; 2s ago
Process: 1153 ExecStart=/home/wakaama-client/bash myscript.sh (code=exited, status=203/EXEC)
Main PID: 1153 (code=exited, status=203/EXEC)
Feb 27 21:18:35 galileo systemd: lwm2m.service: main process exited, code=exited, status=203/EXEC
Feb 27 21:18:35 galileo systemd: Unit lwm2m.service entered failed state.
When i manually run the myscript.sh from terminal it works perfectly fine, but when i followed the mentioned steps and checked the status, i get above error.
myscript.sh file content
lwm2mclient is the binary which i want to get executed on every startup.
can you please help me to resolve this error?
I just changed my script file to below and it worked!
myscript.sh file content
Inshort i gave the full path of the executable and it started working.
But i have another issue is on reboot when i check the status of my service i get following result
lwm2m.service - LWM2M Startup Agent
Loaded: loaded (/lib/systemd/system/lwm2m.service; disabled)
Active: inactive (dead)
I tried changing type = fork as mentioned in some of the forums (Man page systemd.service) but it didn't work. In terminal when i run this command "systemctl start lwm2m.service" but on restart it doesn't, can you please guide me how to fix this?
I some how missed doing "systemcrl enable yourscript.service" and hence i was getting the above error. Its fixed and working now!
Thanks everyone for your help and support!