What does status "active (exited)" mean for a systemd service?

143,976

Solution 1

It seems you are running a system with systemd yet you are using sysV commands. Did you create a sysV init script or a systemd unit file?

State active (exited) means that systemd has successfully run the commands but that it does not know there is a daemon to monitor.

If there is you must define it in the unit file by configuring the Type and ExecStart options appropriately according to whether the process you start is the main proces, forks child processes and exits etc.

Check the different systemd man pages or update your question and post the unit file or init script.

Solution 2

I met the same issue showing active (exited). The root cause is my shell process just quits after it starts some service daemon via start-stop-daemon command.

And the solution is changing my shell process into an infinite loop instead of quitting directly. With this way, it shows active (running) after executing systemctl start my-service-name.service.

Additionally, in this loop the shell process monitors the state of the service daemon. Once the shell process detects the service daemon goes into some error state, it just breaks from the infinite loop and exits.

Share:
143,976

Related videos on Youtube

Highly Irregular
Author by

Highly Irregular

Am currently focused on WordPress website maintenance, management, security, and development. Experience in database driven web application programming, with interests in Bitcoin & cryptocurrencies, intuitive user experiences, PHP, databases, regular expressions, sustainability, and ethics. May have some availability for contract work; feel free to get in touch. Tokens of appreciation are very welcome if you've appreciated my assistance: BTC 1ExE5rD3n3dvmbSXBDtnLLjgGnPkBmfpk3

Updated on September 18, 2022

Comments

  • Highly Irregular
    Highly Irregular over 1 year

    I'm working with a custom service which essentially runs a web server, called thisismywebserver. Currently it's not working (ie I get an "Unable to Connect" error trying to access a page).

    When I run this command service thisismywebserver status to see the status of the service I see that the status is "active (exited)". Does this mean the service has stopped working? If not, then what does this mean?

    root@thisismywebserver-testing:~# service thisismywebserver status
    ● thisismywebserver.service - LSB: ThisIsMyWebServer server
       Loaded: loaded (/etc/init.d/thisismywebserver)
       Active: active (exited) since Sun 2015-11-08 23:01:33 EST; 18h ago
    
    Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
    
  • Highly Irregular
    Highly Irregular over 8 years
    Thanks for your answer! I have just started work on this system since the previous developer became unavailable, so I don't know which of those alternatives applies. I'll have a read of the man pages you mention, and see if I can figure it out.
  • RajSanpui
    RajSanpui over 8 years
    @Bram Can you let us know how to specify that? Is it via the ExecStart and ExecStop ? I am facing same issue
  • Bram
    Bram almost 7 years
    @ whoever downvoted my answer: please comment and explain why you feel this answer is not correct or not complete.
  • JdeBP
    JdeBP over 6 years
    The LSB: in the supplied description tells you that the questioner did not create a service unit, Bram. See unix.stackexchange.com/a/386876/5132 and unix.stackexchange.com/a/387314/5132 .
  • jlh
    jlh almost 6 years
    This state can also mean that the service has been started but its process immediately exited, most likely due to a fatal error. This happened to me with a misconfigured openvpn service.
  • berndbausch
    berndbausch over 3 years
    active (exited) is not a problem in itself. For example, if the unit file sets RemainAfterExit=true, a service that exits is reported as active. Example: On my Ubuntu server, the ufw service initializes the firewall at system startup. It's a oneshot service, which performs one task then exits. However, it's still considered active, perhaps because inactive would confuse users. After all, the firewall is in place.
  • berndbausch
    berndbausch over 3 years
    I said "perhaps because inactive would confuse users". This might be true, but the real reason is to prevent systemctl start ufw to initialize the firewall a second time. Since the service is active, starting it has no effect.
  • azhuang
    azhuang about 3 years
    @berndbausch It's not a problem and the daemon is working fine though it shows "active(exited)" that is a little confusing in the first sight.
  • berndbausch
    berndbausch about 3 years
    See example 4 on the systemd.service manual page: freedesktop.org/software/systemd/man/systemd.service.html.