n8henrie/fauxmo

problem starting fauxmo from Raspian service

johngo7470 opened this issue · 7 comments

  • Issues not following the template may be closed for that reason alone.
  • Operating system and version: Raspian 4.19.66
  • Python version: 3.7
  • Fauxmo version (fauxmo --version): 0.4.9
  • Echo device type (e.g. Echo, Echo Plus, Dot): n/a
  • Echo Firmware Version: n/a

My Issue

Similar to another user, I'm able to start up fauxmo flawlessly, by using the following command, logged in as user 'pi':

 fauxmo -c /home/pi/config.json

pi@raspberrypi:/lib/systemd/system $ fauxmo --version
v0.4.9
pi@raspberrypi:/lib/systemd/system $ whereis fauxmo
fauxmo: /home/pi/.local/bin/fauxmo

The system file contains: ExecStart=/home/pi/.local/bin/fauxmo -c /home/pi/config.json

The problem noted in the system status, is:

 Sep 09 21:23:52 raspberrypi fauxmo[696]:   File "/home/pi/.local/bin/fauxmo", line 6, in <module>
 Sep 09 21:23:52 raspberrypi fauxmo[696]:     from fauxmo.cli import cli
 Sep 09 21:23:52 raspberrypi fauxmo[696]: ModuleNotFoundError: No module named 'fauxmo'
 Sep 09 21:23:52 raspberrypi systemd[1]: myfauxmo.service: Main process exited, code=exited, status=1/FAILURE
 Sep 09 21:23:52 raspberrypi systemd[1]: myfauxmo.service: Failed with result 'exit-code'.

The contents of /home/pi/.local/bin/fauxmo:

 pi@raspberrypi:~/.local/bin $ cat fauxmo
 #!/usr/bin/python3.7
 # -*- coding: utf-8 -*-
 import re
 import sys

 from fauxmo.cli import cli

 if __name__ == '__main__':
     sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
     sys.exit(cli())

==================

On a related note, if fauxmo is installed in a venv (e.g. /home/pi/.venv), how can this be accommodated in a module.service startup script? Do I need to add an activate command to the .service file?

WHYT


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

  • Try to reproduce the issue with Fauxmo installed in a
    venv
  • Ensure you're running a supported version of Python
    • Requires Python >= 3.2 for Fauxmo < 0.3.0
    • Requires Python >= 3.4.4 for Fauxmo >= 0.3.0
    • Requires Python >= 3.6.0 for Fauxmo >= 0.4.0
  • Run Fauxmo in debug mode (-vvv) and include relevant output
  • Include your Fauxmo config.json
  • Search the existing (including closed) issues
  • Please use codeblocks around your debug output and config

I might have figured this one out...

I just noticed your .service example has the .venv version in there - will try this later this evening.

However, what path should be used for the "Working Directory"? (which should probably be moved below the line "#Fix the paths below:")

pi@raspi:/ $ sudo find . -name fauxmo 2>/dev/null
./home/pi/venv/bin/fauxmo
./home/pi/venv/lib/python3.6/site-packages/fauxmo
./usr/local/bin/fauxmo
./usr/local/lib/python3.6/site-packages/fauxmo
./opt/pyenv/versions/3.7.3/bin/fauxmo
./opt/pyenv/versions/3.7.3/lib/python3.7/site-packages/fauxmo
./opt/pyenv/shims/fauxmo

In my particular case, I think I'm using the non-venv version (still trying to understand venv, before I switch to it).

You can ignore workingdirectory (leave it out) if you just use absolute paths, which may be the easiest.

You can probably get the full path to your fauxmo executable with which fauxmo or command -v fauxmo. Use that absolute path and the absolute path to your config and see if that works.

Read up on venvs, they're important to understand!

All paths are fully qualified... does seem like it's missing something from my environment, since it works fine if I execute it unqualified (or fully qualified), from the command line, when logged in as 'pi'.

pi@raspberrypi:~ $ which fauxmo
/home/pi/.local/bin/fauxmo
pi@raspberrypi:~ $ fauxmo --version
v0.4.9

pi@raspberrypi:/ $ sudo systemctl start myfauxmo
pi@raspberrypi:/ $ sudo systemctl status myfauxmo
● myfauxmo.service - Fauxmo
Loaded: loaded (/lib/systemd/system/myfauxmo.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2019-09-12 19:18:52 CDT; 18s ago
Process: 1507 ExecStart=/home/pi/.local/bin/fauxmo -c /home/pi/fauxmo_config.json (code=exited, status=1
Main PID: 1507 (code=exited, status=1/FAILURE)

Sep 12 19:18:52 raspberrypi systemd[1]: Started Fauxmo.
Sep 12 19:18:52 raspberrypi fauxmo[1507]: Traceback (most recent call last):
Sep 12 19:18:52 raspberrypi fauxmo[1507]: File "/home/pi/.local/bin/fauxmo", line 6, in
Sep 12 19:18:52 raspberrypi fauxmo[1507]: from fauxmo.cli import cli
Sep 12 19:18:52 raspberrypi fauxmo[1507]: ModuleNotFoundError: No module named 'fauxmo'
Sep 12 19:18:52 raspberrypi systemd[1]: myfauxmo.service: Main process exited, code=exited, status=1/FAILU
Sep 12 19:18:52 raspberrypi systemd[1]: myfauxmo.service: Failed with result 'exit-code'.

[does seem like it's missing something from my environment]

I created a .venv, and that did the trick... (also seeming to confirm something was missing from my non-venv env)

● myfauxmo.service - Fauxmo
Loaded: loaded (/lib/systemd/system/myfauxmo.service; enabled; vendor preset:
Active: active (running) since Thu 2019-09-12 19:43:29 CDT; 11s ago
Main PID: 1717 (fauxmo)
Tasks: 1 (limit: 4035)
Memory: 7.1M
CGroup: /system.slice/myfauxmo.service
└─1717 /home/pi/.venv/bin/python3 /home/pi/.venv/bin/fauxmo -c /home/

Sep 12 19:43:29 raspberrypi systemd[1]: Started Fauxmo.

I first installed fauxmo using your instructions under "Simple install: From PyPI".

Then, being unsure of using venv, I did a "python3 -m pip remove fauxmo", followed by "python3.7 -m pip install fauxmo".

[And is this your system Python install?]

If I understand your question, yes... It's a Raspberry Pi 4, created a few weeks ago, so it would have likely been created with Python 3.7 from the get-go. When I type 'python3', it shows the version is 3.7.3, whereas on another Raspberry I'm working on (RPi 3), when I start up 'python3', it comes back with 3.5.3, even though I know 3.7.3 is available somewhere (I think via pyenv).

I first installed fauxmo using your instructions under "Simple install: From PyPI".

I don't think this is possible, since my simple install instructions install into a venv, so your fauxmo CLI script would not be in ~/.local/bin. It should definitely have .venv somewhere in its path if you had followed those instructions verbatim.

My guess is at some point you ran into a permissions error and instead ran: python3 -m pip install --user fauxmo. Is that possible?

And then when you ran pip uninstall fauxmo (remove is not a valid pip command to my knowledge) perhaps you got left with an artifact in ~/.local/bin.

Regardless, glad you got it working. venv is the way to go, although Fauxmo doesn't have any dependencies, so theoretically it would probably work fine in a system-wide installation.