CentOS 7下Systemd注册服务

雪域幽狐 2018-02-01 09:34 阅读:8427


在CentOS 6.X,使用的是init.d注册服务,到了CentOS 7后,推荐使用Systemd来注册服务,虽然Systemd有争议,但这个不是本文讨论内容。Systemd相关介绍可使用man查询。
    建立一个service文件,主要涉及下面三节
[Unit]
Description=nowfox-www
After=syslog.target

[Service]
Type=forking
ExecStart=/opt/software/tomcat/tomcat-www/bin/startup.sh
User=tomcat
Group=web

[Install]
WantedBy=multi-user.target

然后在/etc/systemd/system/ 下建立nowfox-www.service连接指向真实的service。
开机启动
systemctl enable nowfox-www

查看开机是否启动
systemctl is-enabled nowfox-www.service

启动
systemctl start nowfox-www

停止
systemctl stop nowfox-www

重启服务
systemctl restart nowfox-www

查看状态
systemctl status nowfox-www

查看日志
journalctl -u nowfox-www

journalctl -f _PID=`ps -ef | grep nowfox-www | grep -v grep | cut -c 10-15`

0条评论

登陆后可评论