CentOS7中系统服务脚本,有系统system和用户user之分
存放system服务启动项路径:/lib/systemd/system/,系统开机没有登录就能运行的服务,754权限保存
存放user服务器启动项路径:/usr/lib/systemd,相应用户登录后才能运行的服务
systemctl list-units --type=service 显示所有系统添加的服务,简介显示
systemctl status 显示所有系统添加的服务,显示详细信息
systemctl start/stop/restart/ sshd.service 启动/关闭/重启指定服务
systemctl enable/disable sshd.service 将服务器添加到开机启动或者不开机启动
service httpd start/stop/restart
启动、关闭、重启服务
systemctl start/stop/restart/ sshd.service
service httpd status 查看指定服务状态 systemctl status httpd.service
chkconfig --list 查看已启动的服务 systemctl list-units --type=service
chkconfig --level 3 httpd on 启动指定服务,在相应运行级别 systemctl enable httd.service
chkconfig --level 3 httpd off 关闭指定服务,在相应运行级别 systemctl disable httd.service
[html] view plaincopyprint?
vim /lib/systemd/system/nginx.service
[plain] view plaincopyprint?
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/www/lanmps/init.d/nginx start
ExecReload=/www/lanmps/init.d/nginx restart
ExecStop=/www/lanmps/init.d/nginx stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径