Ubu18开机自启动

Ubu开机自启动

简单示例
/etc/init.d/目录下新建启动脚本Test

#!/bin/bash
### BEGIN INIT INFO
# Provides: Test
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: autostart service
# Description: 开启自启动脚本
### END INIT INFO
FILE_PATH="/home/***/filePath" #文件路径
FILE_NAME="test.py" #文件名
#开始方法
start() {
# 此处编写程序启动步骤
# eg:
# 1.可执行文件
# cd $FILE_PATH
# nohup ./$FILE_NAME &
#2. 程序文件(python)
# cd $FILE_PATH
# python3 $FILE_NAME &
#3. 直接执行shell命令
# cd /home/cnblog/Form
# python3 test.py
}
#结束方法
stop() {
kill -9 `ps -ef|grep $MY_PATH|grep -v grep|grep -v stop|awk '{print $2}'`
echo "$MY_PATH stop success."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Userage: $0 {start|stop|restart}"
exit 1
esac

2.启动

cd /etc/init.d
sudo systemctl enable Test

Test服务就加入到开机启动过程中
通过systemctl系列命令对服务进行管理,包括status,start,restart

posted @   我才不是老家伙  阅读(52)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2021-02-23 Windows下FFMEPG编译
点击右上角即可分享
微信分享提示