ubuntu自定义服务自动启动

自定义服务

在路径 /etc/systemd/system/ 下 定义example.service
shell 复制代码
[Unit]
Description=My Custom Script

[Service]
ExecStart=/root/exe_start.sh
Type=oneshot
RemainAfterExit=yes


[Install]
WantedBy=multi-user.target

在/root/ 路径下执行

shell 复制代码
 vi exe_start.sh
shell 复制代码
cd /root/mes_server/
nohup python3 manage.py runserver 0:50009 &

可以在exe_start.sh中继续追加其他命令

手动测试
shell 复制代码
sudo systemctl start example.service

访问对应的服务是否启动成功,如果没有启动,查看日志

shell 复制代码
sudo systemctl status example.service
设置开机启动
shell 复制代码
sudo systemctl enable example.service
查看是否设置成功
shell 复制代码
sudo systemctl is-enabled example.service
相关推荐
代码游侠7 小时前
学习笔记——线程
linux·运维·开发语言·笔记·学习·算法
怪只怪满眼尽是人间烟火7 小时前
离线环境下部署区块链FISCO BCOS v2.11.0
linux·运维·区块链
wniuniu_7 小时前
ceph内核模式 和 librbd 模式
运维·服务器·ceph
努力努力再努力wz7 小时前
【Linux网络系列】:网络+网络编程(UDPsocket+TCPsocket)
java·linux·c语言·开发语言·数据结构·c++·centos
姬嘉晗-19期-河北工职大7 小时前
在虚拟机的 Linux 系统(CentOS 7)中搭建一个「虚拟机本地网站」
linux·运维·centos
hkhkhkhkh1237 小时前
Linux 内核三大核心结构体详解(驱动开发视角)
linux·数据结构·驱动开发·字符设备
Smile灬凉城6667 小时前
TCP的四种计时器
运维·服务器·网络
HIT_Weston7 小时前
64、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(八)
前端·ubuntu·gitlab
怪我冷i7 小时前
wsl Ubuntu切换中科大源
linux·windows·ubuntu·ai编程·ai写作
FenceRain7 小时前
Linux 使用脚本删除文件
linux