How to make python program to start automatically after RevPi Core power on
-
- Posts: 38
- Joined: 18 Feb 2019, 04:13
How to make python program to start automatically after RevPi Core power on
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!
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
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.
The better choice is to create a Systemd process which may have dependencies and logging and monitoring capabilities.
-
- Posts: 38
- Joined: 18 Feb 2019, 04:13
Re: How to make python program to start automatically after RevPi Core power on
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!
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!
- Attachments
-
- b.jpg (91.14 KiB) Viewed 9447 times
Re: How to make python program to start automatically after RevPi Core power on
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
-
- Posts: 38
- Joined: 18 Feb 2019, 04:13
Re: How to make python program to start automatically after RevPi Core power on
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.
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.
- Attachments
-
- b.jpg (147.46 KiB) Viewed 9437 times
-
- Posts: 38
- Joined: 18 Feb 2019, 04:13
Re: How to make python program to start automatically after RevPi Core power on
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?
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?
- Attachments
-
- c.jpg (211.97 KiB) Viewed 9432 times
- RevPiModIO
- KUNBUS
- Posts: 335
- Joined: 20 Jan 2017, 08:44
- Contact:
Re: How to make python program to start automatically after RevPi Core power on
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
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
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
-
- Posts: 38
- Joined: 18 Feb 2019, 04:13
Re: How to make python program to start automatically after RevPi Core power on
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!
I have tried RevPiPyLoad service and use revpipycontrol tool to monitor the log of my program. It works well!
Thank you so much!