สร้าง Service ให้ Run สคริปต์ Python ใน Debian
สร้าง service
sudo nano /etc/systemd/system/get_gold.service
ใส่คำสั่ง
[Unit]
Description=Run Python Job (Get Gold)
[Service]
Type=simple
ExecStart=/usr/bin/python3 /mnt/dev/python/Gold001/get_gold.py
WorkingDirectory=/mnt/dev/python/Gold001
User=orangepi
Restart=on-failure
RestartSec=5
โหลด service และเริ่มใช้งาน
sudo systemctl daemon-reload
sudo systemctl start get_gold.service
sudo systemctl enable get_gold.service
ตรวจสอบสถานะ
sudo systemctl status get_gold.service
ดู log แบบเรียลไทม์:
journalctl -u get_gold.service -f
ปล.หากมีการแก้ไขโค๊ดในไฟล์ .py ให้ restart Service ใหม่ โดยใช้คำสั่ง
sudo systemctl restart get_gold.service
ความคิดเห็น
แสดงความคิดเห็น