debian系发行版通过update-rc.d添加服务(service)

之前都是以多以chkconfig来设置自启服务,但是在最近的一些debian发行版中,chkconfig被移除了,这里使用update-rc.d可以替代chkconfig
这里以设置nginx的自启服务为例
1.创建脚本
进入/etc/init.d
创建一个脚本名为nginx,然后

chmod 755 nginx
#!/bin/bash
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6 
# Short-Description: Start nginx at boot time
# Description:       Enable service provided by nginx.
### END INIT INFO

start() 
{
    /opt/nginx_1.8.0/sbin/nginx
    exit 0;
}

stop() 
{
   /opt/nginx_1.8.0/sbin/nginx -s stop
}

case "$1" in
start)
    start
    ;;

stop)
    stop
    ;;

restart)
    stop
    start
    ;;

*)
    echo "Usage: $0 {start|stop|restart}"
    exit 0
    ;;

esac
exit 0

添加为系统服务

update-rc.d nginx defaults 

从系统服务中删除

update-rc.d nginx remove

启动或停止

service nginx start
service nginx stop

或者

systemctl start nginx
systemctl start nginx 

添加以及去除开机自启动

systemctl enable nginx
systemctl disable nginx
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值