== Understanding what '_systemctl restart_' means and when I want to use it Over on Twitter, [[I exposed a _systemctl_ misunderstanding of mine in public https://twitter.com/thatcks/status/1362510255247220739]]: > I wish systemd had a 'systemctl restart-or-start ' option, so > you didn't have to care if you were doing a new install of something > or an upgrade. As [[some https://twitter.com/fbacchella/status/1362511455346700292]] [[people https://twitter.com/_mkfg/status/1362523384043761667]] pointed out to me, I had misunderstood '_systemctl restart_'; this is exactly what it does. For some reason I had it in my mind that '_systemctl restart_' only restarted already running services. Interpreted another way, ~~'_systemctl restart_' insures that the latest (ie current) version of a service is running~~. If it's not running at all it's started (implicitly using the latest version) and if it is running it's stopped and then started again, insuring that it's running the latest version. One corollary of this is that I almost always want to use '_systemctl restart_' in scripts and automation instead of '_systemctl start_', because then the same automation works for both initial installs and upgrades. Often I want to use it interactively as well, since 'restart' is almost entirely a superset of '_systemctl start_'. As I already knew, '_systemctl start_' starts a service if it's not running but doesn't restart it if it is. This is what I want if I want to insure a service is running but *not* restart the service if it already is, for example if stopping and starting a service again is user-visible or disruptive. 'Systemctl start dovecot' is fine if I think Dovecot isn't running and is harmless if I'm wrong and it already has been started. By contrast, 'systemctl restart dovecot' will terminate all current IMAP sessions if Dovecot is already running (although clients usually transparently make new ones). What I thought '_systemctl restart_' did is actually '_systemctl try-restart_', which only stops and starts units that are actually running. Using 'try-restart' is appropriate in things like Let's Encrypt automation, where we don't want renewing a certificate to start up daemons that we've deliberately stopped (or that we never enabled in the first place). There's also 'try-reload-or-restart' which does a '_systemctl reload_' on running units that support it. (Fortunately I don't think any of our current scripts do a 'restart' where we really want a 'try-restart'. All of our daemons that use Let's Encrypt certificates support 'reload', so that's all we're using on them.)