embeded/raspberry pi
라즈베리 파이에 파이썬 스크립트를 서비스로 등록하기
구차니
2024. 8. 27. 16:13
결국은 systemd에 등록인데..
python 프로그램의 경우 pip -g로 인스톨 해서 전역으로 하지 않으면
대부분(?) 에러가 나던데.. 그건 언급이 없네
cd /lib/systemd/system/ sudo nano hello.service The service definition must be on the /lib/systemd/system folder. Our service is going to be called "hello.service": [Unit] Description=Hello World After=multi-user.target [Service] Type=simple ExecStart=/usr/bin/python /home/pi/hello_world.py Restart=on-abort [Install] WantedBy=multi-user.target Here we are creating a very simple service that runs our hello_world script and if by any means is aborted is going to be restarted automatically. You can check more on service's options in the next wiki: https://wiki.archlinux.org/index.php/systemd. Now that we have our service we need to activate it: sudo chmod 644 /lib/systemd/system/hello.service chmod +x /home/pi/hello_world.py sudo systemctl daemon-reload sudo systemctl enable hello.service sudo systemctl start hello.service |
[링크 : https://gist.github.com/emxsys/a507f3cad928e66f6410e7ac28e2990f]