如何在jetson Tx Ubuntu18.04上设置Python脚本开机自启

step 1 第一步,编写脚步执行文件

vim start_script.sh

我的目录是/home/hope-new/picsevrer 大家根据自己目录参考,因为我是Jetson 需要虚拟环境,因此 source 命令

内容如下

#!/bin/bash  
source /home/hope-new/picserver/bin/activate  
cd /home/hope-new/picserver  
exec python yourpythonfile.py

and  next step  : 让文件成为可执行文件

chmod +x start_script.sh

step 2 第二步,编写.service后缀文件

sudo vim /etc/systemd/system/hope.service

我的文件名称是hope.service

内容如下,

[Unit]  
Description=My Python Script  

[Service]  
ExecStart=/home/hope-new/start_script.sh  
WorkingDirectory=/home/hope-new/picserver  
  

# 重启服务时等待进程正常退出  
KillMode=process  

# 设置环境变量(如果需要的话)  
Environment="PATH=/home/hope-new/picserver/bin:$PATH"  

# 确保服务在退出时重启  
Restart=always  

[Install]  
WantedBy=multi-user.target

step 3 生效

sudo systemctl enable hope.service
sudo systemctl start hope.service


可以查看运行状态

sudo systemctl status hope.service

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值