nandanator
nandanator

Reputation: 481

systemctl status shows inactive dead

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

Answers (2)

Vadiraj S J
Vadiraj S J

Reputation: 717

Few points:

  1. If you use Type=forking, it is recommended to specify PidFile.

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

  3. use systemctl start service-name to start a service

  4. Then use systemctl status service-name to check its status. status will be inactive/dead if service is not started.

Upvotes: 12

Mark Stosberg
Mark Stosberg

Reputation: 13381

  • You have set Type=Forking, but your service doesn't work. Try Type=oneshot
  • You have a "&" your ExecStart line, which is not necessary.
  • The service is 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

Related Questions