Reputation: 481
I am trying to write my own (simple) systemd service which does something simple.( Like writing numbers 1 to 10 to a file, using the shell script). My service file looks like below.
[Unit]
Description=NandaGopal
Documentation=https://google.com
After=multi-user.target
[Service]
Type=forking
RemainAfterExit=yes
ExecStart=/usr/bin/hello.sh &
[Install]
RequiredBy = multi-user.target
This is my shell script.
#!/usr/bin/env bash
source /etc/profile
a=0
while [ $a -lt 10 ]
do
echo $a >> /var/log//t.txt
a=`expr $a + 1`
done
For some reason, the service doesn't come up and systemctl is showing the below output.
root@TARGET:~ >systemctl status -l hello
* hello.service - NandaGopal
Loaded: loaded (/usr/lib/systemd/system/hello.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: https://google.com
Been trying to figure out what went wrong for the last 2 days.
Upvotes: 37
Views: 170566
Reputation: 717
Few points:
If you use Type=forking
, it is recommended to specify PidFile.
In your case, Type=simple
, and ExecStart without &
will work.
use systemctl start service-name
to start a service
Then use systemctl status service-name
to check its status.
status will be inactive/dead if service is not started.
Upvotes: 12
Reputation: 13381
Type=Forking
, but your service doesn't work. Try
Type=oneshot
ExecStart
line, which is not necessary. disabled
, which means it was not enabled
to start at boot. You should run systemctl enable hello
to set it to start at boot.You can check man systemd.directives
to find an index of all the directives that you can use in your unit
files.
Upvotes: 49