ubuntu与Centos添加开启启动
来源:嵌入式技术笔记 发布时间:2022-12-17
分享至微信

Ubuntu添加开机启动
两步添加开机启动,如下
1.编写开机脚本
这个脚本需要放在/etc/init.d/下面
#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/test
NAME=test
DESC=test
PID=/var/run/test/test.pid
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile $PID \
--name $NAME --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon -K --quiet --pidfile $PID \
--name $NAME
killall -9 dc
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon -K --quiet --pidfile $PID \
--name $NAME
sleep 1
start-stop-daemon --start --quiet --pidfile $PID \
--name $NAME --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile $PID \
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >2
exit 1
;;
esac
exit 0
2.添加到开机启动
update-rc.d test defaults 91
test 就是第一步中编写的脚本名称,在/etc/ini.d目录下面。通过这条命令,就可以把该应用添加到开机启动了。
Centos添加开机启动
与Ubuntu方法类似, 也需要两步,只是脚本和命令有点区别:
1.脚本
#! /bin/sh
#chkconfig: 2345 60 82
#description: Starttest
此处省略N个子
2.添加到开机启动
chkconfig --add test #添加启动
chkconfig #查看当前启动列表
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
test 0:关 1:关 2:开 3:开 4:开 5:开 6:关
mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[ 新闻来源:嵌入式技术笔记,更多精彩资讯请下载icspec App。如对本稿件有异议,请联系微信客服specltkj]
存入云盘 收藏
举报
全部评论
暂无评论哦,快来评论一下吧!

嵌入式技术笔记
嵌入式linux应用开发;C/C++技术交流;Qt编程交流;技术文章分享
查看更多
相关文章
群联与Lonestar联手,开启人类数据存储新时代
2025-02-28
群联电子:NAND Flash回暖与AI共振,开启增长新周期
2025-03-11
MWC 2025:5G-A与AI主导,6G军备赛悄然开启
2025-03-14
热门搜索
视源股份考虑在香港二次上市
晶丰明源2024年营收超15亿元
华为
台积电
中芯国际
联发科
高通
英特尔
芯片