linux添加开机启动项

本文介绍了如何在三种不同的Linux发行版(Ubuntu、CentOS、Gentoo)中设置服务的自启动。对于Ubuntu和CentOS,需要创建并配置特定格式的脚本,并通过系统命令将其加入启动队列。而在Gentoo中,则需要将脚本放置于指定目录内。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ubuntu:

1.编写脚本xxx放于/etc/init.d/下

2.修改脚本执行权限:chmod 755 xxx

3.update-rc.d xxx defaults NN (NN为启动顺序),将脚本添加到系统启动执行的队列中去。

 

centos:

1.编写chkconfig格式的脚本xxx,放于/etc/init.d/下:

 

#/bin/sh
#chkconfig: 2345 20 80  
#description: nginx script,2345运行级 20是启动时优先级 80是关闭时优先级
case $1 in
          start)  /usr/bin/nginx             ;;
          stop)   /usr/bin/nginx -s quit     ;;
              *)  echo "require start|stop"  ;;
esac

2.修改脚本执行权限:chmod 755 xxx

3.添加服务:chkconfig --add xxx 

 

gentoo:

看下/etc/local.d/README这个文件,里面说的很清楚了

This directory should contain programs or scripts which are to be run

when the local service is started or stopped.

 

If a file in this directory is executable and it has a .start extension,

it will be run when the local service is started. If a file is

executable and it has a .stop extension, it will be run when the local

service is stopped.

 

All files are processed in lexical order.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值