How to auto start Linux application when system boot?


#1

I want to launch hello_world example Linux application when Linux system boot.

How to do that ?

Thanks


#2

You probably want to do this when the user logs in, not when the system boots. If you’re using the Altera GSRD, look at adding/modifying ~/.profile to run your application.


#3

Thank you. :heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart:


#4

refer to link: http://stackoverflow.com/questions/14149477/auto-start-program-at-login-in-angstrom-on-beagleboard

Found the answer: The script /etc/profile is ran when the user logs in.
You can add a line to start your application at the end it.


#5

The /etc/rc.local script can be used for launch application without logging in.


#6

It’s a better option. :slight_smile:


#7

root@socfpga:~# systemctl -l status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2017-09-22 18:57:09 UTC; 1min 13s ago
Process: 1283 ExecStart=/etc/rc.local start (code=exited, status=203/EXEC)

Sep 22 18:57:08 socfpga systemd[1]: Starting /etc/rc.local Compatibility…
Sep 22 18:57:09 socfpga systemd[1]: rc-local.service: Control process exited, code=exited status=203
Sep 22 18:57:09 socfpga systemd[1]: Failed to start /etc/rc.local Compatibility.
Sep 22 18:57:09 socfpga systemd[1]: rc-local.service: Unit entered failed state.
Sep 22 18:57:09 socfpga systemd[1]: rc-local.service: Failed with result ‘exit-code’.
root@socfpga:~#


#8

Run applications as services on startup:

In order to run an application as a service on startup, create a file named “.service” in the folder “/etc/systemd/system/” with the following contents:

[Unit]
Description=Service description
After=network.target

[Service]
User=
Group=
ExecStart=
Restart=always

[Install]
WantedBy=multi-user.target

Example running a python application called triangle-detector-server.py:

[Unit]
Description=Triangle Detector Server

[Service]
Type=simple
WorkingDirectory=/home/root/triangle-detector-server
ExecStart=/home/root/.virtualenvs/uvicamera/bin/python triangle-detector-server.py

[Install]
WantedBy=multi-user.target


#9

I have this working but i needed to add the service to startup after doing this.

just type systemctl enable xxxx.service

xxxx = name of your service