Page 1 of 1
How to make python program to start automatically after RevPi Core power on
Posted: 06 Mar 2019, 09:43
by hikaru2001
Hello,
I make a small python program and want to make it start automatically after RevPi Core 3 power on.
Could you tell me how to do it. Thank you!
Re: How to make python program to start automatically after RevPi Core power on
Posted: 06 Mar 2019, 14:01
by dirk
Hi the quick and dirty solution is to put the command to execute your program into "/etc/rc.local" just before line "exit 0".
The better choice is to create a
Systemd process which may have dependencies and logging and monitoring capabilities.
Re: How to make python program to start automatically after RevPi Core power on
Posted: 07 Mar 2019, 08:32
by hikaru2001
Hi Dirk,
I try the second way. I create a myscript.service file.
----------------------------------------------------------------------------------
[Unit]
Description=My service
After=network.target
[Service]
ExecStart=/usr/bin/python3 -u main.py
WorkingDirectory=/home/pi/myscript
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
--------------------------------------------------------------------------
And copy the file to /etc/systemd/system
I also create a simply main.py
------------------------------------------------------------
print("PILZ")
-----------------------------------------------------------
However when I use command"sudo systemctl start myscript.service" and enter, there is nothing happen on my terminal.
Could you pls find the reason?
Thank you!
Re: How to make python program to start automatically after RevPi Core power on
Posted: 07 Mar 2019, 09:48
by dirk
Hey thats a good start. Usually background processes use to print to log files and avoid stdout. There are many options available for the parameter "StandardOutput" have a look here:
https://www.freedesktop.org/software/sy ... .exec.html
Re: How to make python program to start automatically after RevPi Core power on
Posted: 07 Mar 2019, 10:17
by hikaru2001
Hi Dirk,
I want to realize the function when RevPi Core 3 power on, it will go into Python interface and show me the status of running. Then I can monitor the function like the picture.
Re: How to make python program to start automatically after RevPi Core power on
Posted: 07 Mar 2019, 10:49
by hikaru2001
Something to append:
My real python program will access to Internet service and write to a cloud server. Should the python program start automatically after the network of RevPi is recovered when it is powered on?
Re: How to make python program to start automatically after RevPi Core power on
Posted: 07 Mar 2019, 12:42
by RevPiModIO
Alternatively you can use our RevPiPyLoad service, which will autostart you Python program and monitors it.
Have a look:
https://revpimodio.org/en/revpipyplc-2/revpipyload/
You can install a GUI on a computer in your network to send the program to the RevPi and read the logs and things like that
Regards, Sven
Re: How to make python program to start automatically after RevPi Core power on
Posted: 08 Mar 2019, 05:45
by hikaru2001
Hi Sven,
I have tried RevPiPyLoad service and use revpipycontrol tool to monitor the log of my program. It works well!
Thank you so much!