Can I make systemd show service status after starting or stopping a service?
Solution 1:
There's no built-in command for your use-case so you'll have to make an alias for your favorite shell or a trivial script wrapper.
Solution 2:
I also needed it, so I made it a shell script function.
# Usage
# sc start nginx
# sc start nginx php74-php-fpm
function sc {
name="${@:(2)}";
echo "COMMAND: ${1}, NAME: ${name}";
systemctl "${1}" ${name};
systemctl status ${name};
}
Reduces the command entry process as follows.
#systemctl start nginx; systemctl status nginx
sc start nginx
This is the command added to /root/.basrc in CentOS 7.
echo 'function sc { name="${@:(2)}"; echo "COMMAND: ${1}, NAME: ${name}"; systemctl "${1}" ${name}; systemctl status ${name}; }' >> ~/.bashrc && source ~/.bashrc
Run sc start nginx
COMMAND: start, NAME: nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since 토 2020-11-21 11:36:11 KST; 49s ago
Docs: http://nginx.org/en/docs/
Process: 31713 ExecStop=/bin/sh -c /bin/kill -s TERM $(/bin/cat /var/run/nginx.pid) (code=exited, status=0/SUCCESS)
Process: 31718 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 31719 (nginx)
CGroup: /system.slice/nginx.service
├─31719 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
├─31720 nginx: worker process
├─31721 nginx: worker process
├─31722 nginx: worker process
├─31723 nginx: worker process
├─31724 nginx: worker process
└─31725 nginx: worker process
11월 21 11:36:11 dev5.php79.com systemd[1]: Starting nginx - high performance web server...
11월 21 11:36:11 dev5.php79.com systemd[1]: Started nginx - high performance web server.
Gist - https://gist.github.com/ibin79/4d1d0b5c48ebbc70730292a96ae367d9