linux之将程序改为系统启动&开机自动启动

1.sudo vim /etc/systemd/system/django_ops.service

2.填入以下内容

[Unit]
Description=My Custom Service
After=network.target

[Service]
ExecStart=/data/soft/django_ops/django_ops.sh
Restart=always

[Install]
WantedBy=multi-user.target
View Code

3.所用脚本内容

/data/soft/django_ops/django_ops.sh

#!/bin/bash
python3 /data/soft/django_ops/manage.py runserver 0.0.0.0:8000
View Code

4.可以执行以下命令

sudo systemctl daemon-reload # 重新加载所有的服务
sudo systemctl start django_ops.service # 启动你的服务
sudo systemctl enable django_ops.service # 设置服务开机自启

5.过程不顺利的话可以使用一下查看日志报错

sudo journalctl -u django_ops.service

6.查看开机自启的程序列表

systemctl list-unit-files --type=service | grep enabled

 

posted @ 2023-08-29 12:20    阅读(7)  评论(0编辑  收藏  举报