Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

systemctl status shows inactive dead

Tags:

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.

like image 489
nandanator Avatar asked Oct 05 '16 10:10

nandanator


2 Answers

  • 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.

like image 116
Mark Stosberg Avatar answered Sep 17 '22 16:09

Mark Stosberg


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.

like image 34
Vadiraj S J Avatar answered Sep 16 '22 16:09

Vadiraj S J