systemctl status shows inactive dead

nandanator picture nandanator · Oct 5, 2016 · Viewed 65.1k times · Source

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.

Answer

Mark Stosberg picture Mark Stosberg · Oct 5, 2016
  • 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.