Jessie Startup Scripts

From embeddedTS Manuals
Revision as of 12:24, 12 February 2016 by Mark (talk | contribs) (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=...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

To have your headless application start up on poweron you need to create a service. Create a file in /etc/systemd/system/yourapp.service

[Unit]
Description=Run an application on startup

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

[Install]
WantedBy=multi-user.target

If you depend on networking you should add "After=network.target" in the Unit section. Once you have this file in place add it to startup with:

# Start your app automatically on bootup, but will not start it now
systemctl enable yourapp.service

# Start your app now, but doesn't change auto startup
systemctl start yourapp.service
Note: See the systemd documentation for in depth documentation on services.

To automatically start an application with graphics on X11 you should instead change the x-session-manager. By default the system starts xfce:

root@ts:~# ls -lah /usr/bin/x-session-manager 
lrwxrwxrwx 1 root root 35 May 26  2015 /usr/bin/x-session-manager -> /etc/alternatives/x-session-manager
root@ts:~# ls -lah /etc/alternatives/x-session-manager
lrwxrwxrwx 1 root root 19 May 26  2015 /etc/alternatives/x-session-manager -> /usr/bin/startxfce4

You can create your own x-session with just your required processes. Create the file /usr/bin/mini-x-session with these contents:

#!/bin/bash
matchbox-window-manager -use_titlebar no &

exec xfce4-terminal

You may need to "apt-get install matchbox-window-manager." first. This is a tiny window manager which also has a few flags that simplify embedded use. Now enable this session manager and restart slim to restart x11 and show it now.

chmod a+x /usr/bin/mini-x-session
rm /etc/alternatives/x-session-manager
ln -s /usr/bin/mini-x-session /etc/alternatives/x-session-manager
service slim restart

If you type exit from the terminal on the screen you will notice the slim/x11 processes will restart. If the x-session-manager process ever closes x11 will restart. The exec command will have your process take over that process id when it runs, so if it ever exits it will restart slim/x11.