Why does ghost-cli set nginx.service to Restart=always instead of Restart=on-failure

This article states the following:

First, ExecStart tells systemd what command it should run to launch our app. Then, Restart tells systemd under what conditions it should restart the app if it sees that it has died. The on-failure value is likely what you will want. Using this, the app will NOT restart if it goes away “cleanly”. Going away “cleanly” means that it either exits by itself with an exit value of 0 , or it gets killed with a “clean” signal, such as the default signal sent by the kill command. Basically, if our app goes away because we want it to, then systemd will leave it turned off. However, if it goes away for any other reason (an unhandled exception crashes the app, for example), then systemd will immediately restart it for us. If you want it to restart no matter what, change the value from on-failure to always .

Ghost-CLI sets systemd config for nginx as restart=always:

[Service]
Type=simple
WorkingDirectory=<%= dir %>
User=<%= user %>
Environment="NODE_ENV=<%= environment %>"
ExecStart=<%= ghost_exec_path %> run
Restart=always <================================

In fact, as the article explains, I just tried to run a small experiment. I found a ghost process PID and killed it with kill command. Within a few seconds, the process was restarted by systemd although it wasn’t failure, it was a clean process stop.

Is that intentional? What’s the rationale behind it? Thanks!

While I can’t say if it’s intentional, it can be rationalized. As you shouldn’t be trying to control the state of your instance outside of the cli, even if ghost cleanly exits, it should be restarted since you didn’t make it exit via the cli. Again, this might not be the reason, it’s just a possible rationalisation.

Thanks! I’m not a big fan of CLIs do be honest :slightly_smiling_face:, I always prefer to know what I’m doing :). Do you think I could get an answer on github by creating an issue?

@maxkoretskyi apologies for not replying sooner - was a bit confused by the issue title (we don’t modify nginx.service, we only create a new ghost systemd service that Ghost-CLI manages)

As far as why it’s set to restart=always, that honestly may have just been because when I implemented that bit of the CLI, I wasn’t as familiar with systemd and the different options it had available. Plus, @vikaspotluri123 is right in that the original intent was to not control the state of the instance outside the CLI.

That said, there have since been improvements to other areas of Ghost-CLI that should enable us to set it to on-failure without causing any issues.

There are several improvements that I want to make to how we use systemd in the CLI, can add this to the list.

1 Like

Thanks a lot for your reply and clarifications, @acburdine! I have plans to start contributing to Ghost and Ghost-CLI in the future, that’s why I try to understand particular low-level details :). Good luck!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.