You ran the deprecated command service nginx status
and got output similar to this:
error@vmtest-ubuntu1604:~$ sudo service nginx status
* nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Active: active (running) since Mon 2019-03-04 10:44:30 EST; 13s ago
Main PID: 16843 (nginx)
CGroup: /system.slice/nginx.service
|-16843 nginx: master process /usr/sbin/nginx -g daemon on; master_pr
|-16844 nginx: worker process
`-16845 nginx: worker process
Mar 04 10:44:30 vmtest-ubuntu1604 systemd[1]: Starting A high performance web se
Mar 04 10:44:30 vmtest-ubuntu1604 systemd[1]: Started A high performance web ser
lines 1-11/11 (END)
Upon which you didn't get the terminal prompt back.
First, this command is deprecated because Ubuntu 16.04 replaced upstart with systemd. The service
command now attempts to translate your command into the corresponding systemd command, in this case systemctl status nginx
. This is what was actually run, and what actually generated the output you saw. In a future Ubuntu release, the service
command will be removed entirely.
What's going on?
By default in current versions of systemd, systemctl
pipes the status output through a pager, by default less
.
You can turn this behavior off by passing --no-pager
in the command, in which case the output will just be dumped to standard out, and your terminal comes back immediately.
error@vmtest-ubuntu1604:~$ sudo systemctl --no-pager status nginx
* nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-03-04 10:44:30 EST; 3min 33s ago
Main PID: 16843 (nginx)
CGroup: /system.slice/nginx.service
|-16843 nginx: master process /usr/sbin/nginx -g daemon on; master...
|-16844 nginx: worker process
`-16845 nginx: worker process
Mar 04 10:44:30 vmtest-ubuntu1604 systemd[1]: Starting A high performance web...
Mar 04 10:44:30 vmtest-ubuntu1604 systemd[1]: Started A high performance web ...
Hint: Some lines were ellipsized, use -l to show in full.
error@vmtest-ubuntu1604:~$
Note that this output isn't meant to be machine-parsed. If you are trying to check service status in shell scripts. you should use other systemctl
commands, such as systemctl is-active
.
error@vmtest-ubuntu1604:~$ sudo systemctl is-active --quiet nginx && echo Running || echo Stopped
Running
error@vmtest-ubuntu1604:~$ sudo systemctl stop nginx
error@vmtest-ubuntu1604:~$ sudo systemctl is-active --quiet nginx && echo Running || echo Stopped
Stopped