Yocto startup scripts systemd: Difference between revisions

From embeddedTS Manuals
(Created page with "To have your headless application start up on poweron you need to create a service. Create a file in /etc/systemd/system/yourapp.service <source lang=ini> [Unit] Description=...")
 
(Clean up text and grammar)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
To have your headless application start up on poweron you need to create a service.  Create a file in /etc/systemd/system/yourapp.service
To have a custom headless application start up at boot a systemd service needs to be created.  Create the file <source lang=bash inline>/etc/systemd/system/yourapp.service</source> with contents similar to below:
<source lang=ini>
<source lang=ini>
[Unit]
[Unit]
Line 12: Line 12:
</source>
</source>


The multi-user.target will start up early, but if you depend on networking you should use "network.service".  Once you have this file in place add it to startup with:
If an application depends on networking, the systemd script will want to have <source lang=bash inline>After=network.target</source> in the Unit section.  Once this file is in place, it can be added to automatic startup with the following:
<source lang=bash>
<source lang=bash>


# Start your app automatically on bootup, but will not start it now
# Enable the application to be started on boot up
systemctl enable yourapp.service
systemctl enable yourapp.service


# Start your app now, but doesn't change auto startup
# Start the application now, but will not affect automatic startup
systemctl start yourapp.service
systemctl start yourapp.service
</source>
</source>


{{Note|See the [http://www.freedesktop.org/software/systemd/man/systemd.service.html systemd documentation] for in depth documentation on services.}}
{{Note|See the [http://www.freedesktop.org/software/systemd/man/systemd.service.html systemd documentation] for in depth documentation on services.}}
To set up a graphical application startup, modify the <source lang=bash inline>/usr/bin/mini-x-session</source> file
At the end of the script replace <source lang=bash inline>matchbox-terminal</source> with the desired application (absolute path may need to be specified):
<source lang=bash>
matchbox-terminal &
exec matchbox-window-manager
</source>
The exec statement must be last in the script in order to take over this script's PID for correct operation.

Latest revision as of 16:25, 23 March 2020

To have a custom headless application start up at boot a systemd service needs to be created. Create the file /etc/systemd/system/yourapp.service with contents similar to below:

[Unit]
Description=Run an application on the i.MX6

[Service]
Type=simple
ExecStart=/usr/local/bin/your_app_or_script

[Install]
WantedBy=multi-user.target

If an application depends on networking, the systemd script will want to have After=network.target in the Unit section. Once this file is in place, it can be added to automatic startup with the following:

# Enable the application to be started on boot up
systemctl enable yourapp.service

# Start the application now, but will not affect automatic startup
systemctl start yourapp.service
Note: See the systemd documentation for in depth documentation on services.

To set up a graphical application startup, modify the /usr/bin/mini-x-session file

At the end of the script replace matchbox-terminal with the desired application (absolute path may need to be specified):

matchbox-terminal &
exec matchbox-window-manager

The exec statement must be last in the script in order to take over this script's PID for correct operation.