systemctl 和 status 命令有什么作用?

systemctl 和 status 命令有什么作用?

当我运行时,例如:

systemctl status nut-monitor.service

systemd 是做什么的?

如果我查看单元文件,我找不到任何线索:

 cat /usr/lib/systemd/system/nut-monitor.service
[Unit]
Description=Network UPS Tools - power device monitor and shutdown controller
After=local-fs.target network.target nut-server.service

[Service]
ExecStartPre=-/usr/bin/systemd-tmpfiles --create /etc/tmpfiles.d/nut-run.conf
ExecStart=/usr/sbin/upsmon -F
Type=simple

[Install]
WantedBy=multi-user.target

答案1

man systemctl

Show terse runtime status information about one or more units, followed by most recent log data from the journal.
           If no units are specified, show system status. If combined with --all, also show the status of all units (subject
           to limitations specified with -t). If a PID is passed, show information about the unit the process belongs to.

           This function is intended to generate human-readable output. If you are looking for computer-parsable output, use
           show instead. By default this function only shows 10 lines of output and ellipsizes lines to fit in the terminal
           window. This can be changes with --lines and --full, see above. In addition, journalctl --unit=NAME use a similar
           filter for messages and might be more convenient.

基本上systemctl status会显示服务是否正在运行、是否已启用,并且会显示 systemd 日志的最后 10 行。

journalctl --unit=servicename | tail -10您可以通过执行类似操作获得相同的日志输出journalctl --unit=sshd | tail -10

相关内容