Search code examples
linuxbashdebiansystemdsystemctl

Systemctl status shows Succeeded, but service is inactive


I have this simple /etc/systemd/system/test.service file

[Unit]
Description=SkriptA
After=network.target auditd.service

[Service]
Type=simple
ExecStart=/opt/test.sh

[Install]
WantedBy=multi-user.target

When i run systemctl start test.service and then systemctl status test.service It shows that serivce succeeded but is inacitve, please why is this?

● test1.service - SkriptA
   Loaded: loaded (/etc/systemd/system/test1.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Mar 05 12:17:55 hro0078 systemd[1]: Started SkriptA.
Mar 05 12:17:55 hro0078 systemd[1]: test1.service: Succeeded.

The ExecStart script is simple as service

#!/usr/bin/bash

echo Hi > /tmp/test1
date >> /tmp/test1

I use: Linux version 4.19.0-13-amd64 ([email protected]) (gcc version 8.3.0 (Debian 8.3.0-6)) #1 SMP Debian 4.19.160-2 (2020-11-28)


Solution

  • Your program was started successfully and it terminated directly.

    To have your service active, it needs to keep running. Example:

    #!/usr/bin/bash
    
    while [ 1 ]; do
        echo Hi > /tmp/test1
        date >> /tmp/test1
        sleep 60
    done