1 关于自定义的一个service,以nginx为例
[root@localhost ~]# cat /usr/lib/systemd/system/nginx.service [Unit] Description=System Nginx Service Wants=network.target network-online.target After=network.target network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target
相关参数解释
https://www.cnblogs.com/wjb10000/p/5566801.html
https://blog.csdn.net/comprel/article/details/82750288
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
systemd 的日志管理 journalctl
journalctl -k 查看内核日志(不显示应用日志)
journalctl -f 实时滚动显示最新日志
journalctl -u nginx.service 查看某个unit的日志
# 查看指定时间的日志
journalctl --since="2012-10-30 18:17:16"
journalctl --since "20 min ago"
journalctl --since yesterday
journalctl --since "2015-01-10" --until "2015-01-11 03:00"
journalctl --since 09:00 --until "1 hour ago"
查看指定进程的日志
journalctl _PID=1