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

The service won't start properly #108

Closed port3r closed 3 years ago

port3r commented 3 years ago

My Issue

I have installed python 3.7.3 to debian distribution DietPi, python installation was successull. I continue with simple install.

When I run fauxmo from console Alexa found my devices. But when I set Fauxmo run as service and restart Raspberry, Alexa don't recognize my devices, when I delete them Alexa don't find them. Only if I run command from console.

I installed fauxmo as root, and installation is in root directory, it's a problem? When I run in console, work properly: /root/.venv/bin/fauxmo -c /etc/fauxmo/config.json -vvv

but as service not. I copied service script from extras and update paths My fauxmo.service in etc/systemd/system/fauxmo.service

[Unit]
Description=Fauxmo
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
WorkingDirectory=/root/.venv/lib/python3.7/site-packages/fauxmo
# Fix the paths below:
ExecStart=/root/.venv/bin/fauxmo -c /etc/fauxmo/config.json -v
Restart=on-failure
RestartSec=10s
User=fauxmo

[Install]
WantedBy=multi-user.target 

My etc/fauxmo/config.json

{
    "FAUXMO": {
        "ip_address": "auto"
    },
    "PLUGINS": {
        "SimpleHTTPPlugin": {
            "path": "/root/.venv/lib/python3.7/site-packages/fauxmo/plugins/",
            "DEVICES": [
                {
                    "on_cmd": "http://192.168.0.200/on",
                    "off_cmd": "http://192.168.0.200/off",
                    "method": "GET",
                    "name": "Fan"
                },
            ]
        }
    }
}

WHYT


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

n8henrie commented 3 years ago

Please search the issues -- there are a few with similar problems.

My first thought is that you installed to /root but are running as user fauxmo. That's probably not right -- please address this.

port3r commented 3 years ago

I read all issues but I found nothing. Ok, I will try install again, but I have not linux user. Please help me.

Please write my steps, like.

  1. login as user pi, fauxmo doesn't exist
  2. create fauxmo user -> command add user...
  3. install python
  4. ..

Thank for your help...

n8henrie commented 3 years ago

https://github.com/n8henrie/fauxmo/issues/101 is relevant

This is a general linux problem and not a fauxmo problem.

Your fauxmo user needs to have access to the directory, but it won't if you're putting your files into the root folder. You need to set appropriate permissions on the folder for fauxmo to be able to see those files.

For testing, you need to be running as the fauxmo user (e.g. with sudo -u fauxmo /path/to/fauxmo -c /path/to/config.json)

Also please follow the issue template -- you did not include any logs to help confirm this is the issue.

port3r commented 3 years ago

I add new user fauxmo and install on it fauxmo with commands

> python3 -m venv .venv
> source ./.venv/bin/activate
> python3 -m pip install fauxmo
> Make a fauxmo.config.json on fauxmo home directory
> fauxmo -c fauxmo.config.json [-v]

edit my config to

{
    "FAUXMO": {
        "ip_address": "auto"
    },
    "PLUGINS": {
        "SimpleHTTPPlugin": {
            "DEVICES": [
                {
                    "port": 12340,
                    "on_cmd": "http://192.168.0.200/on",
                    "off_cmd": "http://192.168.0.200/off",
                    "method": "GET",
                    "name": "Fan"
                },
            ]
        }
    }
}

I run it from console under fauxmo user fauxmo -c fauxmo.config.json -v

but Alexa nothing discovered...

port3r commented 3 years ago

My log is here There is other devices

{
    "FAUXMO": {
        "ip_address": "auto"
    },
    "PLUGINS": {
        "SimpleHTTPPlugin": {
            "DEVICES": [
                {
                    "port": 12340,
                    "on_cmd": "http://192.168.0.200/fanON",
                    "off_cmd": "http://192.168.0.200/fanOFF",
                    "method": "GET",
                    "name": "Fan"
                },
                {
                    "port": 12341,
                    "on_cmd": "http://192.168.0.201/toggle",
                    "off_cmd": "http://192.168.0.201/toggle",
                    "method": "GET",
                    "name": "Door"
                }
            ]
        }
    }
}
port3r commented 3 years ago

When I setup service after reboot i check it

root@DietPi:~# systemctl status fauxmo
● fauxmo.service - Fauxmo
   Loaded: loaded (/etc/systemd/system/fauxmo.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Mon 2021-02-01 21:29:20 CET; 2s ago
  Process: 651 ExecStart=/home/fauxmo/.venv/bin/fauxmo -c /home/fauxmo/fauxmo.config.json -v (code=exited, status=200/CHDIR)
 Main PID: 651 (code=exited, status=200/CHDIR)

is this correct? Service is online? because when i type htop command I don't see any process fauxmo

n8henrie commented 3 years ago

Did you move your fauxmo config somewhere?

Again, it is probably not going to work if you put your config in /root (which the fauxmo user can't read) but then run as user fauxmo.

You need to make a directory somewhere that the fauxmo user can access and put your config there.

port3r commented 3 years ago

Yes, as you can see on service status it works from /home/fauxmo with user fauxmo. I can't run service via systemctl. But I setup cron and run it as @reboot it works.

I read my log and I recognized that simpleHTTPPlugin need to set device state parameter. I don't know check device state, but I set "use_fake_state": true and it works now.

n8henrie commented 3 years ago

I'm not sure if I understood correctly. Is it now working? If so, please close the issue.

port3r commented 3 years ago

Yes, it's working, but service don't want to start, I need to use cron. Fauxmo now find all devices, it was possible to set use_fake_state in config.json

n8henrie commented 3 years ago

Glad it's working with cron. I'm not clear if you followed my instructions to get it working with systemd.

I run it from console under fauxmo user

How are you running it as the fauxmo user? Is your fauxmo user a login user? If so you should probably move your fauxmo stuff into /home/fauxmo and check your permissions.

If not a login user, you need to be running it with sudo -u fauxmo (or equivalent), otherwise you won't be able to tell why it doesn't run with systemd.

n8henrie commented 3 years ago

Better yet, please show me the exact command you're using to run Fauxmo from the console, and also show me the output of whoami.

port3r commented 3 years ago

In console I run /home/fauxmo/.venv/bin/fauxmo -c fauxmo.config.json -vvv

whoami command output fauxmo

port3r commented 3 years ago

but never mind, it's working now with cron...

n8henrie commented 3 years ago

/home/fauxmo/.venv/bin/fauxmo -c fauxmo.config.json -vvv

Can you include the full path to fauxmo.config.json? Did you move it?

Also output from journalctl -xf -b -u fauxmo.service.

but never mind, it's working now with cron...

¯\(ツ)

port3r commented 3 years ago

Output from command

fauxmo@DietPi:~ $ journalctl -xf -b -u fauxmo.service
Hint: You are currently not seeing messages from other users and the system.
      Users in the 'systemd-journal' group can see all messages. Pass -q to
      turn off this notice.
No journal files were opened due to insufficient permissions.

Fauxmo config is in home directory /home/fauxmo/fauxmo.config.json

port3r commented 3 years ago

Output from root

root@DietPi:~# journalctl -xf -b -u fauxmo.service
-- Logs begin at Wed 2021-02-03 02:59:41 CET. --
Feb 03 08:18:48 DietPi systemd[1]: fauxmo.service: Main process exited, code=exited, status=200/CHDIR
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit fauxmo.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 200.
Feb 03 08:18:48 DietPi systemd[1]: fauxmo.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit fauxmo.service has entered the 'failed' state with result 'exit-code'.
Feb 03 08:18:58 DietPi systemd[1]: fauxmo.service: Service RestartSec=10s expired, scheduling restart.
Feb 03 08:18:58 DietPi systemd[1]: fauxmo.service: Scheduled restart job, restart counter is at 4839.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Automatic restarting of the unit fauxmo.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Feb 03 08:18:58 DietPi systemd[1]: Stopped Fauxmo.
-- Subject: A stop job for unit fauxmo.service has finished
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A stop job for unit fauxmo.service has finished.
--
-- The job identifier is 305048 and the job result is done.
Feb 03 08:18:58 DietPi systemd[1]: Started Fauxmo.
-- Subject: A start job for unit fauxmo.service has finished successfully
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit fauxmo.service has finished successfully.
--
-- The job identifier is 305048.
Feb 03 08:18:58 DietPi systemd[6918]: fauxmo.service: Changing to the requested working directory failed: No such file or directory
Feb 03 08:18:58 DietPi systemd[6918]: fauxmo.service: Failed at step CHDIR spawning /home/fauxmo/.venv/bin/fauxmo: No such file or directory
-- Subject: Process /home/fauxmo/.venv/bin/fauxmo could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The process /home/fauxmo/.venv/bin/fauxmo could not be executed and failed.
--
-- The error number returned by this process is ERRNO.
Feb 03 08:18:58 DietPi systemd[1]: fauxmo.service: Main process exited, code=exited, status=200/CHDIR
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit fauxmo.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 200.
Feb 03 08:18:58 DietPi systemd[1]: fauxmo.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit fauxmo.service has entered the 'failed' state with result 'exit-code'.
Feb 03 08:19:08 DietPi systemd[1]: fauxmo.service: Service RestartSec=10s expired, scheduling restart.
Feb 03 08:19:08 DietPi systemd[1]: fauxmo.service: Scheduled restart job, restart counter is at 4840.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Automatic restarting of the unit fauxmo.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Feb 03 08:19:08 DietPi systemd[1]: Stopped Fauxmo.
-- Subject: A stop job for unit fauxmo.service has finished
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A stop job for unit fauxmo.service has finished.
--
-- The job identifier is 305111 and the job result is done.
Feb 03 08:19:08 DietPi systemd[1]: Started Fauxmo.
-- Subject: A start job for unit fauxmo.service has finished successfully
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit fauxmo.service has finished successfully.
--
-- The job identifier is 305111.
Feb 03 08:19:08 DietPi systemd[6941]: fauxmo.service: Changing to the requested working directory failed: No such file or directory
Feb 03 08:19:08 DietPi systemd[6941]: fauxmo.service: Failed at step CHDIR spawning /home/fauxmo/.venv/bin/fauxmo: No such file or directory
-- Subject: Process /home/fauxmo/.venv/bin/fauxmo could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The process /home/fauxmo/.venv/bin/fauxmo could not be executed and failed.
--
-- The error number returned by this process is ERRNO.
Feb 03 08:19:08 DietPi systemd[1]: fauxmo.service: Main process exited, code=exited, status=200/CHDIR
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit fauxmo.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 200.
Feb 03 08:19:08 DietPi systemd[1]: fauxmo.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit fauxmo.service has entered the 'failed' state with result 'exit-code'.
Feb 03 08:19:18 DietPi systemd[1]: fauxmo.service: Service RestartSec=10s expired, scheduling restart.
Feb 03 08:19:18 DietPi systemd[1]: fauxmo.service: Scheduled restart job, restart counter is at 4841.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Automatic restarting of the unit fauxmo.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Feb 03 08:19:18 DietPi systemd[1]: Stopped Fauxmo.
-- Subject: A stop job for unit fauxmo.service has finished
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A stop job for unit fauxmo.service has finished.
--
-- The job identifier is 305174 and the job result is done.
Feb 03 08:19:18 DietPi systemd[1]: Started Fauxmo.
-- Subject: A start job for unit fauxmo.service has finished successfully
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit fauxmo.service has finished successfully.
--
-- The job identifier is 305174.
Feb 03 08:19:18 DietPi systemd[6942]: fauxmo.service: Changing to the requested working directory failed: No such file or directory
Feb 03 08:19:18 DietPi systemd[6942]: fauxmo.service: Failed at step CHDIR spawning /home/fauxmo/.venv/bin/fauxmo: No such file or directory
-- Subject: Process /home/fauxmo/.venv/bin/fauxmo could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The process /home/fauxmo/.venv/bin/fauxmo could not be executed and failed.
--
-- The error number returned by this process is ERRNO.
Feb 03 08:19:18 DietPi systemd[1]: fauxmo.service: Main process exited, code=exited, status=200/CHDIR
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit fauxmo.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 200.
Feb 03 08:19:18 DietPi systemd[1]: fauxmo.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit fauxmo.service has entered the 'failed' state with result 'exit-code'.
Feb 03 08:19:28 DietPi systemd[1]: fauxmo.service: Service RestartSec=10s expired, scheduling restart.
Feb 03 08:19:28 DietPi systemd[1]: fauxmo.service: Scheduled restart job, restart counter is at 4842.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Automatic restarting of the unit fauxmo.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Feb 03 08:19:29 DietPi systemd[1]: Stopped Fauxmo.
-- Subject: A stop job for unit fauxmo.service has finished
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A stop job for unit fauxmo.service has finished.
--
-- The job identifier is 305237 and the job result is done.
Feb 03 08:19:29 DietPi systemd[1]: Started Fauxmo.
-- Subject: A start job for unit fauxmo.service has finished successfully
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit fauxmo.service has finished successfully.
--
-- The job identifier is 305237.
Feb 03 08:19:29 DietPi systemd[6943]: fauxmo.service: Changing to the requested working directory failed: No such file or directory
Feb 03 08:19:29 DietPi systemd[6943]: fauxmo.service: Failed at step CHDIR spawning /home/fauxmo/.venv/bin/fauxmo: No such file or directory
-- Subject: Process /home/fauxmo/.venv/bin/fauxmo could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The process /home/fauxmo/.venv/bin/fauxmo could not be executed and failed.
--
-- The error number returned by this process is ERRNO.
Feb 03 08:19:29 DietPi systemd[1]: fauxmo.service: Main process exited, code=exited, status=200/CHDIR
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit fauxmo.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 200.
Feb 03 08:19:29 DietPi systemd[1]: fauxmo.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit fauxmo.service has entered the 'failed' state with result 'exit-code'.
Feb 03 08:19:39 DietPi systemd[1]: fauxmo.service: Service RestartSec=10s expired, scheduling restart.
Feb 03 08:19:39 DietPi systemd[1]: fauxmo.service: Scheduled restart job, restart counter is at 4843.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Automatic restarting of the unit fauxmo.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Feb 03 08:19:39 DietPi systemd[1]: Stopped Fauxmo.
-- Subject: A stop job for unit fauxmo.service has finished
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A stop job for unit fauxmo.service has finished.
--
-- The job identifier is 305300 and the job result is done.
Feb 03 08:19:39 DietPi systemd[1]: Started Fauxmo.
-- Subject: A start job for unit fauxmo.service has finished successfully
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit fauxmo.service has finished successfully.
--
-- The job identifier is 305300.
Feb 03 08:19:39 DietPi systemd[6944]: fauxmo.service: Changing to the requested working directory failed: No such file or directory
Feb 03 08:19:39 DietPi systemd[6944]: fauxmo.service: Failed at step CHDIR spawning /home/fauxmo/.venv/bin/fauxmo: No such file or directory
-- Subject: Process /home/fauxmo/.venv/bin/fauxmo could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The process /home/fauxmo/.venv/bin/fauxmo could not be executed and failed.
--
-- The error number returned by this process is ERRNO.
Feb 03 08:19:39 DietPi systemd[1]: fauxmo.service: Main process exited, code=exited, status=200/CHDIR
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit fauxmo.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 200.
Feb 03 08:19:39 DietPi systemd[1]: fauxmo.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit fauxmo.service has entered the 'failed' state with result 'exit-code'.
n8henrie commented 3 years ago

Here's your error: systemd[6941]: fauxmo.service: Changing to the requested working directory failed: No such file or directory Feb 03 08:19:08 DietPi systemd[6941]: fauxmo.service: Failed at step CHDIR spawning /home/fauxmo/.venv/bin/fauxmo: No such file or directory Need to make sure your WorkingDirectory is a directory (the above is probably a file).

port3r commented 3 years ago

Working directory is set to /home/fauxmo/.venv/lib/python3.7/site-package/fauxmo is this correct? In this directory is located extras plugins and also fauxmo.py file.

port3r commented 3 years ago

My fauxmo.service

[Unit]
Description=Fauxmo
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
WorkingDirectory=/home/fauxmo/.venv/lib/python3.7/site-package/fauxmo
# Fix the paths below:
ExecStart=/home/fauxmo/.venv/bin/fauxmo -c /home/fauxmo/fauxmo.config.json -v
Restart=on-failure
RestartSec=10s
User=fauxmo

[Install]
WantedBy=multi-user.target
port3r commented 3 years ago

Now I realized, that I was wrong path... site-package is site-packages Wrrrrrrrr.... I'm stupid.

port3r commented 3 years ago

I edited my service to correct working path, service working after reboot now. It was stupid error, sorry, but thanks for your help, without your helping hand, thanks a lot.

n8henrie commented 3 years ago

site-package is site-packages

Yes I just saw that too.

Also, this is an odd place to put things and will be problematic when you upgrade python. I strongly recommend you move your config and any personal settings or personal files (like plugins you've added) elsewhere, for example /home/fauxmo would be a much more natural place.

port3r commented 3 years ago

Thanks for all, and thanks for your Fauxmo!