Linux设置服务和开机启动
将Python脚本设置为开机服务
- 创建service文件
sudo vim /etc/systemd/system/backup-tool.service
[Unit]
Description=Backup Tool Python Script
After=network.target
[Service]
Type=oneshot
User=h3c
ExecStart=/home/h3c/miniconda3/bin/python /home/h3c/backup_tool/main.py
WorkingDirectory=/home/h3c/backup_tool
[Install]
WantedBy=multi-user.target
- 启动服务和自启
sudo systemctl daemon-reload
sudo systemctl start backup-tool.service
sudo systemctl status backup-tool.service
sudo systemctl enable backup-tool.service # 启用开机自启

浙公网安备 33010602011771号