Systemctl status shows inactive dead

I am trying to write my own (simple) systemd service that does something simple. (How to write numbers from 1 to 10 in a file using a shell script). My service file looks 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 does not appear, and systemctl shows the following result.

 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 

I tried to find out what went wrong in the last 2 days. Can anyone help me here?

Regards, nandanator

+7
linux sh systemd systemctl
source share
2 answers
  • You set Type=Forking , but your service is down. Try Type=oneshot
  • You have "&" your ExecStart line, which is not needed.
  • The service is disabled , which means that it was not enabled at boot time. You must run systemctl enable hello to start it at boot.

You can check man systemd.directives to find the index of all directives that you can use in your unit files.

+6
source share

A few points:

  • If you use Type=forking , it is recommended that you specify PidFile.

  • In your case, Type=simple and ExecStart without & will work.

  • use systemctl start service-name to start the service

  • Then use systemctl status service-name to check its status. the status will be inactive / dead if the service is not running.

+1
source share

All Articles