I have some Pi2 and Pi3 which communicate with python scripts.
As i need these scripts to automatically restart if needed, i try to start the scripts as a service on each Pi and then to start and stop the service in crontab.
I followed the help below to "start a python script as service" :
http://www.diegoacuna.me/how-to-run-a-s ... an-jessie/
-
My service is in /systemd/system.... It is named pymotion.service.
My problems are twice :
- the script run at "/" point, i would like it runs where the script is ("/media/pi/USB/pyde motion/171106 pyde_motion.py"), because it runs with files and numerous relatives paths.
- if i enable the service, it will start on boot (?), then i added in crontab to stop it on system start. Is it correct ? (i'm not sure if it will not start after)
Code: Select all
[Unit]
Description=PyDemon Motion ALPR
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python "/media/pi/USB/pyde motion/171106 pyde_motion.py"
RootDirectory="/media/pi/USB/pyde motion" # this command doesn't work !!!!!!!!!!!!!!!!!!!!?
WorkingDirectory="/media/pi/USB/pyde motion" # this command doesn't work !!!!!!!!!!!!!!!!!!!!?
Restart=on-abort
[Install]
WantedBy=mutli-user.target
Code: Select all
# crontab to specify when to run the script as a service
@reboot sudo systemctl stop pymotion.service
50 6 * * * sudo systemctl start pymotion.service
45 16 * * * sudo systemctl stop pymotion.service

