n8henrie / fauxmo

Emulated Belkin WeMo devices that work with the Amazon Echo
https://n8henrie.com/2016/02/fauxmo-home-automation-with-the-amazon-echo-raspberry-pi-and-homeassistant/
Other
376 stars 78 forks source link

systemd startup issue #86

Closed johngo7470 closed 5 years ago

johngo7470 commented 5 years ago

My Issue

When I try to start fauxmo from a systemd service file, I see the following information in the log file:

● myfauxmo.service - Fauxmo
   Loaded: loaded (/etc/systemd/system/myfauxmo.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2019-09-21 19:25:15 EDT; 13s ago
  Process: 423 ExecStart=/opt/pyenv/versions/3.7.3/bin/fauxmo -c /home/pi/fauxmo_config.json (code=exited, status=1/FAILURE)
 Main PID: 423 (code=exited, status=1/FAILURE)

Sep 21 19:25:14 raspi fauxmo[423]:   File "/opt/pyenv/versions/3.7.3/lib/python3.7/site-packages/fauxmo/cli.py", line 37, in cli
Sep 21 19:25:14 raspi fauxmo[423]:     main(config_path_str=args.config, verbosity=verbosity)
Sep 21 19:25:14 raspi fauxmo[423]:   File "/opt/pyenv/versions/3.7.3/lib/python3.7/site-packages/fauxmo/fauxmo.py", line 64, in main
Sep 21 19:25:14 raspi fauxmo[423]:     fauxmo_ip = get_local_ip(fauxmo_config.get("ip_address"))
Sep 21 19:25:14 raspi fauxmo[423]:   File "/opt/pyenv/versions/3.7.3/lib/python3.7/site-packages/fauxmo/utils.py", line 37, in get_local_ip
Sep 21 19:25:14 raspi fauxmo[423]:     tempsock.connect(("8.8.8.8", 0))
Sep 21 19:25:14 raspi fauxmo[423]: OSError: [Errno 101] Network is unreachable
Sep 21 19:25:15 raspi systemd[1]: myfauxmo.service: Main process exited, code=exited, status=1/FAILURE
Sep 21 19:25:15 raspi systemd[1]: myfauxmo.service: Unit entered failed state.
Sep 21 19:25:15 raspi systemd[1]: myfauxmo.service: Failed with result 'exit-code'.

Is this because my network interface isn't quite ready yet?

I can still start it manually with: nohup /opt/pyenv/versions/3.7.3/bin/fauxmo -c /home/pi/fauxmo_config.json &, but I would prefer to just have it start automatically.

I removed Restart=on-failure from my service startup, because early on, I had a typo in my config.json, and it seemed to be putting my RPi in a state where I couldn't telnet into it (ended up breaking out the monitor/mouse/keybd), presumably because it was rolling restarts my fauxmo service.

Is there a reason Restart=on-failure was added to the .service startup file? Should I re-add it, now that my config.json appears to be configured properly?

WHYT


Please make sure you've taken these steps before submitting a new issue:

n8henrie commented 5 years ago

Yes, likely trying to start before your network is ready.

The specifics of your startup file will depend a lot on your specific machine and configuration, and there are lots of ways to skin this cat.

I recommend reading through https://www.freedesktop.org/software/systemd/man/systemd.service.html and paying special attention to settings like

Wants=network-online.service After=network-online.service

Or there is another service that is something like network-wait-online.service; it may work better but requires a separate service to be enabled, and that service has been failing lately on my arch Linux box, so I can't say whether or not it's a more or less robust way to go than the other options.

These should help systemd wait until the network is up to start fauxmo.

Alternatively, there is a setting that is something like BootSec= that will just wait a configurable amount of time after booting, which works fairly well.

Finally, there are settings like Restart and RestartSec that will automatically try to restart the service if it fails (possibly after waiting a configurable amount of time).

Lots of options here. I'm mobile and this is from memory; let me know if this helps you sort through things.

johngo7470 commented 5 years ago

Good to know details on systemd... I ended up adding Restart=on-failure, and it works - thank you!