0

Having already queried on the matter of syntax for restarting a server and having modified nginx.service by adding Restart=always for a few servers, a few weeks later I find the configuration file is devoid of this option.

Could I possibly have misconfigured the option in the wrong block ([Service]) or is there a mechanism by which this file is overwritten and reset to a default state?

What is a sound approach to monitoring this situation, as one of the servers nginx has decided to fall over frequently (possibly daily - a suspect is letsencrypt renewal verifications process) ?

[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target

[Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;' ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;' ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid TimeoutStopSec=5 KillMode=mixed

[Install] WantedBy=multi-user.target

Jerome
  • 139
  • Which file did you modify — the file in /lib (or /usr/lib), or the file in /etc? – Stephen Kitt Nov 28 '22 at 09:43
  • definitely not /etc . I do not recall which of /usr/lib of /lib but had noticed they were symlinked. Just checked: directory /etc/systemd/system has no reference to nginx.service in either of the servers – Jerome Nov 28 '22 at 09:47
  • Got the answer and am implementing. Is the position of the option in a given block relevant? – Jerome Nov 28 '22 at 10:01
  • Not for Restart=, but why is that a concern? Your override file should only have [Service] followed by Restart=…. (Incidentally, if you have a comment on an answer, you should comment on the answer; I only got notified of your comment in this instance because I’d commented on the question myself.) – Stephen Kitt Nov 28 '22 at 10:03

1 Answers1

1

Files under /lib or /usr/lib “belong” to the system’s package management system and must not be modified; package updates will overwrite your changes. This is likely what happened here.

You should add your specific settings in snippets, using systemctl edit; see How can I make a modification to a .service and keep it persistent? for details.

Stephen Kitt
  • 434,908
  • [got it!] Maybe I misinterpreted the docs. I considered the two avenues, possibly mistakenly, and decided on wanting to see all the vendor settings & editing from that. I thus copied the file and edited that. Pitfalls in this approach? – Jerome Nov 28 '22 at 10:07
  • 1
    Copying the complete file means the unit is entirely overridden, which means you won’t get any improvements made to the unit file in the package. – Stephen Kitt Nov 28 '22 at 10:17