以设置httpd开机自启动为例
指令 |
service指令
|
systemctl
指令
|
launchctl指令(Mac)
|
编写启动脚本目录 |
vi /etc/init.d/httpd
|
vi /usr/lib/systemd/system/httpd.service
vi /etc/systemd/system/httpd.service
|
~/Library/LaunchAgents 由用户自己定义的任务项
/Library/LaunchAgents 由管理员为用户定义的任务项
/Library/LaunchDaemons 由管理员定义的守护进程任务项
/System/Library/LaunchAgents 由Mac OS X为用户定义的任务项
/System/Library/LaunchDaemons 由Mac OS X定义的守护进程任务项
|
脚本赋权 |
chmod +x /etc/init.d/httpd
|
chmod +x /usr/lib/systemd/system/httpd.service
| |
使某服务自动启动
|
Centos:
chkconfig -–level 3 httpd on
chkconfig --add
httpd
Ubuntu:
update-rc
.d
httpd
defaults
|
systemctl enable httpd.service
|
launchctl load -w com.httpd.plist
|
使某服务不自动启动
|
Centos:
chkconfig –-level 3 httpd off
chkconfig —del
httpd
Ubuntu:
update-rc.d -f
httpd
remove
|
systemctl disable httpd.service
|
launchctl unload -w com.httpd.plist
|
检查服务状态
|
service httpd status
|
systemctl status httpd.service
| |
显示所有已启动的服务
|
chkconfig –-list
|
systemctl list-units --type service
|
launchctl list | grep 'com.httpd'
|
启动某服务
|
service httpd start
|
systemctl start httpd.service
|
launchctl start com.httpd.plist
|
停止某服务
|
service httpd stop
|
systemctl stop httpd.service
|
launchctl stop com.httpd.plist
|
重启某服务
|
service httpd restart
|
systemctl restart httpd.service
|
launchctl restart com.httpd.plist
|
重载某服务
|
systemctl reload httpd.service
|