How to setup systemd file to start up bash scrip in clear linux?

I tried to setup my systemd file to run .sh file to run one license file during start up.
I made my shell script in /usr/local/bin/my_file.sh

and I created Unit file at /etc/systemd/system/my_service.service

with data as
[Unit]
Description=Test systemd service.

[Service]
Type=Simple
ExecStart=/bin/bash /usr/local/bin/my_file.sh

[Install]
WantedBy=multi-user.target

is there anything which I might be doing wrong ? cause it used to work with the same way in other linux.

It is showing the error “Caught signal 15 and exiting”, is it due to my script or other issue ?

Thank you.

with

chmod +x my_file 

and start your file with a shebang you can run it direct without /bin/bash in your unit file. in some case you may want some evironment variables or another shell. have you tried simply running the script without the unit to see if it works?

this is no different on clear than anywhere else. a simple systemctl start my_service will run any matching file name under /etc/systemd/system/ , as a service.

You may need Type=oneshot instead if the script exits quickly.

1 Like

yes, I tried to work the script normally and it is working. The problem has been solved, I needed to add the information to keep it running after exit, also gave it root permission and it somehow worked.

[Unit]
Description=Example systemd service.

[Service]
Type=simple
User=root
ExecStart=/bin/bash /usr/local/bin/my_file.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target