Why?komarek wrote:i never used thattpylkko wrote:Do you mean that you don't know what a user service is?
See this for example, then:
https://wiki.archlinux.org/index.php/Systemd/User
just didnt know ittpylkko wrote:Why?komarek wrote:i never used thattpylkko wrote:Do you mean that you don't know what a user service is?
See this for example, then:
https://wiki.archlinux.org/index.php/Systemd/User
Code: Select all
#!/bin/bash
sleep 60s
LOG_FILE="/home/pi/Documents/PY/analitico.log"
echo "Starting analitico.py.." >> $LOG_FILE
/usr/bin/python3 /home/pi/Documents/PY/analitico.py &>> $LOG_FILE
service analitico status:NotRequired wrote:I have one final suggestion based on the "sleep" idear earlier in the thread. First remove the "EnvironmentFile" line from your service, then modify your analitico.sh to:
This will wait for 60 seconds before the PY script is executed.Code: Select all
#!/bin/bash sleep 60s LOG_FILE="/home/pi/Documents/PY/analitico.log" echo "Starting analitico.py.." >> $LOG_FILE /usr/bin/python3 /home/pi/Documents/PY/analitico.py &>> $LOG_FILE
Code: Select all
● analitico.service - Servizio Gestione Google Analytics su MQTT
Loaded: loaded (/lib/systemd/system/analitico.service; enabled)
Active: failed (Result: exit-code) since dom 2017-07-02 14:27:53 CEST; 1min 58s ago
Process: 31202 ExecStart=/home/pi/Documents/SH/analitico.sh (code=exited, status=203/EXEC)
Main PID: 31202 (code=exited, status=203/EXEC)
lug 02 14:27:53 pitre systemd[1]: Started Servizio Gestione Google Analytics su MQTT.
lug 02 14:27:53 pitre systemd[1]: analitico.service: main process exited, code=exited, status=203/EXEC
lug 02 14:27:53 pitre systemd[1]: Unit analitico.service entered failed state.
analitico was emptyNotRequired wrote:Is the line "Starting analitico.py.." added to the analitico log? If not try to put "TimeoutStartSec=infinity" in your [Service] section of the service.
Code: Select all
[Unit]
Description=Servizio Gestione Google Analytics su MQTT
After=multi-user.target
Wants=network.target network-online.target
[Service]
User=pi
Type=idle
TimeoutStartSec=infinity
ExecStart=/home/pi/Documents/SH/analitico.sh
[Install]
WantedBy=multi-user.target
Code: Select all
● analitico.service - Servizio Gestione Google Analytics su MQTT
Loaded: loaded (/lib/systemd/system/analitico.service; enabled)
Active: failed (Result: exit-code) since dom 2017-07-02 15:04:06 CEST; 1min 39s ago
Process: 16045 ExecStart=/home/pi/Documents/SH/analitico.sh (code=exited, status=203/EXEC)
Main PID: 16045 (code=exited, status=203/EXEC)
lug 02 15:04:06 pitre systemd[1]: Started Servizio Gestione Google Analytics su MQTT.
lug 02 15:04:06 pitre systemd[1]: analitico.service: main process exited, code=exited, status=203/EXEC
lug 02 15:04:06 pitre systemd[1]: Unit analitico.service entered failed state.
i had to chamod 777 /home/pi/Documents/SH/analitico.sh to make it runNotRequired wrote:If you run the shell script from the command line, does it add a line to analitico.log?
EDIT: Can you start the service manually with: "sudo systemctl start analitico"?
yes you're rightNotRequired wrote:If you run analitico.sh from the command line, it MUST add a line to analitico.log before it starts the py script. If it does not there must be a typo in the path or something. If you run the command: "echo "Added a line" >> /home/pi/Documents/PY/analitico.log" it must also add a line.
Code: Select all
Starting analitico.py..
Code: Select all
● analitico.service - Servizio Gestione Google Analytics su MQTT
Loaded: loaded (/lib/systemd/system/analitico.service; enabled)
Active: active (running) since dom 2017-07-02 15:57:31 CEST; 1min 42s ago
Main PID: 8658 (analitico.sh)
CGroup: /system.slice/analitico.service
├─8658 /bin/bash /home/pi/Documents/SH/analitico.sh
└─9221 /usr/bin/python3 /home/pi/Documents/PY/analitico.py
lug 02 15:57:31 pitre systemd[1]: Started Servizio Gestione Google Analytics su MQTT.
Code: Select all
Starting analitico.py..
Code: Select all
Starting analitico.py..
Code: Select all
Starting analitico.py..
DEBUG ATTEMPT ANALITICO
Traceback (most recent call last):
File "/home/pi/Documents/PY/analitico.py", line 135, in <module>
client.loop_forever()
File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 1410, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 911, in loop
socklist = select.select(rlist, wlist, [], timeout)
KeyboardInterrupt
i dont know if it's working butFerdinand wrote:Perhaps you may try this:
edit in your home directory the file autostart in the directory .config/lxsession/LXDE-pi
And add the following line:
@lxterminal -e './Documents/PY/analitico.py'
Reboot your machine.
noFerdinand wrote:Did you try:
sudo journalctl -u <your application>.service > <your log file>
noFerdinand wrote:This you follow this tutorial?
https://learn.adafruit.com/diy-esp8266- ... i?view=all
sorry that's not the problemFerdinand wrote:I think I found your problem in your original setup (rc.local). Your network is not yet running after a reboot, so you have to wait a couple of seconds.
analitico.py
add the following line just after import time
time.sleep(20)
rc.local
edit the line "python3 /home/pi/Documents/PY/analitico.py &" into
"python3 /home/pi/Documents/PY/analitico.py > /home/pi/Documents/PY/analitico.log"
reboot your system (don't forget to disable analitico.service on your system)
I tested my setup with iot.eclipse.org
i dont think i understand what you meantpylkko wrote:I think it sounds like a good idea to start the mqtt as a background system service and run the script autostarted from the desktop, since then the script will run with the pi user and have the same session and environment as when it is run manually. But it will not work when /if you are using a Raspbian without graphicall desktop to begin with
You are daemon-reloading when you test changes to the service? If you post all the required data to get to the point where you are now, I could try to see if I can get it to work