How I can "start" if service is not running, but "reload" if it is running using systemd?

by berkes   Last Updated October 19, 2019 22:00 PM - source

I have deployment (capistrano) that, on success, reloads systemd:

sudo systemd reload myserver.service

But, just after the first deploy, the service is not yet running. In that case, I want to start it, instead.

sudo systemd start myserver.service

Is there a flag or other trick in systemd that figures out: "is the service running, then reload, otherwise, start it"? The alternative would be to build this into the deployment tooling itself, but I'd rather use existing features if systemd provides these.

Tags : systemd

Answers 1

You probably mixed something up. The command to reload or start a systemd service is systemctl.
You can try

sudo systemctl reload-or-restart myserver.service

That should do what You asked for.

October 20, 2019 08:28 AM

Related Questions

NTP reach property equivalent for timedatectl command

Updated September 30, 2019 15:00 PM