I noticed that many of the commands like nginx -s reload and nginx -s stop seem to be (almost?) the same as service nginx reload and service nginx stop.

Are those "prefixes" actually interchangable? Does one of them somehow invoke the other?

  • What system and version are you running? – Piotr P. Karwasz Jan 20 at 21:57
  • @PiotrP.Karwasz Ubuntu Server 18.04 and Nginx 1.14.0. – Džuris Jan 21 at 20:05

Since you are running Ubuntu 18.04 (i.e. a recent Linux distribution), I might suggest a third “alias” command: systemctl reload nginx and /etc/init.d/nginx reload.

The whole story is this: every server/application has its own way to start, stop, reload, etc. This might be as simple as calling nginx or complicated as setting several environment variables and calling java <a_lot_of_options> org.apache.catalina.startup.Bootstrap start for Tomcat.

In order to provide a uniform and automatic way to start applications, distributions provide init scripts (or similar), which on a new Ubuntu come in three variants:

  1. The modern systemd: systemctl <verb> nginx,
  2. The legacy (for Ubuntu) upstart: service nginx <verb>,
  3. The oldest SysV init: /etc/init.d/nginx <verb>.

On Ubuntu systemd is the actual one running, while the other ones call systemd. The configuration (/lib/systemd/system/nginx.service file) for nginx contains:

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


  • systemctl reload nginx calls nginx -s reload, but with the additional option -g 'daemon on; master_process on;', which overrides these two configuration options,
  • systemctl stop nginx uses a helper program start-stop-daemon to supervise nginx shutdown. This program will send a SIGQUIT signal to nginx, which is the same as nginx -s quit, wait 5 seconds and if nginx is still running announce failure.

In general it is better to use the systemctl <verb> <service> commands instead of starting applications by themselves.

Edit: Actually systemd does much more than executing the command: it connects its input/output to systemd-journald, it limits the resources at its disposal (cgroups) and the visibility of other parts of the system (namespaces), it configures the process capabilities and probably something more.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.