1

I have a service that should run set of applications in background on my Yocto embedded Linux system. I don't like an idea to create a systemd startup script for each app so I just run them from a bash script as following:

The service:

startup.service

[Unit]
Description=applications startup script
After=network.target

[Service]
Type=simple
ExecStart=/opt/somedir/startup.sh

[Install]
WantedBy=multi-user.target

and the script

startup.sh

#!/bin/bash

echo "application startup script"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/somedir
/opt/somedir/app1 &
/opt/somedir/app2 &
/opt/somedir/app3 &

But no application started. Checking the service status give me:

systemctl status startup

● startup.service - applications startup script
   Loaded: loaded (/lib/systemd/system/startup.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2021-03-25 10:33:16 UTC; 18min ago
  Process: 428 ExecStart=/opt/somedir/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 428 (code=exited, status=0/SUCCESS)

Mar 25 10:33:16 systemd[1]: Started application startup script.
Mar 25 10:33:16 startup.sh[428]: application startup script
Mar 25 10:33:16 systemd[1]: startup.service: Succeeded.

So the service executed on the system startup and executes the script. If I execute the script from the command line it starts the applications as expected. So what a reason that no application run?

1
  • Research Type=simple what does it do, and how does it differ from other Type=s. Commented Mar 25, 2021 at 18:06

2 Answers 2

5

Systemd will need to know how to run the script. Therefore either add:

#!/bin/bash

to the top line of the startup.sh script or change the ExecStart line in the systemd service file to:

ExecStart=/bin/bash -c /opt/somedir/startup.sh

Also, to ensure that the processes spawned remain persistent after being spawned, change:

Type=forking
Sign up to request clarification or add additional context in comments.

5 Comments

Sorry I have this line in my script, just lost it while copying. I've updated my question.
Try the second method
Yes, already tried that, the same result. systemctl status startup shows the echo output, the status is successful but no applications run after the service starting and no error/warning messages.
Change the service type to forking. I have added to the solution
Bingo! That works! Thank you @Raman Sailopal you've been very helpful.
1

systemd runs script startup.sh, and after that process ends, it assumes all is done so it kills off any remaining processes and the unit ends. The simplest solution is to add a wait at the end of startup.sh so that it only returns when the backgrounded processes have all ended.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.