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?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
Since you are running Ubuntu 18.04 (i.e. a recent Linux distribution), I might suggest a third “alias” command:
systemctl reload nginx and
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:
systemctl <verb> nginx,
service 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 nginxcalls
nginx -s reload, but with the additional option
-g 'daemon on; master_process on;', which overrides these two configuration options,
systemctl stop nginxuses a helper program
start-stop-daemonto supervise nginx shutdown. This program will send a
SIGQUITsignal 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.