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
相关推荐
AlfredZhao18 小时前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
zzzzzz3102 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
A小辣椒4 天前
TShark:Wireshark CLI 功能
linux
A小辣椒4 天前
TShark:基础知识
linux
AlfredZhao4 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao5 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334665 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪5 天前
linux 拷贝文件或目录到指定的位置
linux
大树886 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai