Setting up AppDaemon service on Hasbian issues

I think my ExecStart is not correct for Hasbian.
If it is wrong, what should it be …

If that is not the issue then here is more info …
You can see from the screenshot I am on Hasbian.

My home directory is

Here is where I think I am wrong, but I not seeing it …

Try changing the hass service name in the requires:

[email protected]

Also, I don;t think that is the right path for the AppDaemon executable. What does the following give you?

$ type appdaemon

I’m capturing your responses so I can update the docs and get a working set of instructions for hassbian :slight_smile:

Made progress. The type showed me what I needed for the ExecStart.
I made the change and rebooted, still showed failed. I updated my service start config.
Here is a screen shot showing you the type command, my config, and showing the ExecStart is now configure (I copy it and ran it on the command line, at bottom.

Here is a sudo journalctl -u [email protected]

pi@hassbian:~ $ sudo journalctl -u  [email protected]
-- Logs begin at Fri 2017-07-14 15:51:52 UTC, end at Fri 2017-07-14 16:02:50 UTC. --
Jul 14 15:52:02 hassbian systemd[1]: Starting AppDaemon...
Jul 14 15:52:02 hassbian systemd[1]: Started AppDaemon.
Jul 14 15:52:02 hassbian systemd[1]: [email protected]: main process exited, code=exited, status=217/USER
Jul 14 15:52:02 hassbian systemd[1]: Unit [email protected] entered failed state.
Jul 14 15:58:33 hassbian systemd[1]: Stopped AppDaemon.
Jul 14 15:59:01 hassbian systemd[1]: Starting AppDaemon...
Jul 14 15:59:01 hassbian systemd[1]: Started AppDaemon.
Jul 14 15:59:01 hassbian systemd[1]: [email protected]: main process exited, code=exited, status=217/USER
Jul 14 15:59:01 hassbian systemd[1]: Unit [email protected] entered failed state.
pi@hassbian:~ $

Here is another look without the -u

Jul 14 15:58:33 hassbian sudo[924]: pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/systemctl stop [email protected]
Jul 14 15:58:33 hassbian sudo[924]: pam_unix(sudo:session): session opened for user root by pi(uid=0)
Jul 14 15:58:33 hassbian systemd[1]: Stopped AppDaemon.
Jul 14 15:58:33 hassbian sudo[924]: pam_unix(sudo:session): session closed for user root
Jul 14 15:59:01 hassbian sudo[936]: pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/systemctl start [email protected]
Jul 14 15:59:01 hassbian sudo[936]: pam_unix(sudo:session): session opened for user root by pi(uid=0)
Jul 14 15:59:01 hassbian systemd[1]: Starting AppDaemon...
Jul 14 15:59:01 hassbian systemd[1]: Started AppDaemon.
Jul 14 15:59:01 hassbian systemd[942]: Failed at step USER spawning /usr/local/bin/appdaemon: No such process
Jul 14 15:59:01 hassbian systemd[1]: [email protected]: main process exited, code=exited, status=217/USER
Jul 14 15:59:01 hassbian sudo[936]: pam_unix(sudo:session): session closed for user root
Jul 14 15:59:01 hassbian systemd[1]: Unit [email protected] entered failed state.
Jul 14 16:00:09 hassbian sudo[957]: pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/journalctl -u [email protected]
Jul 14 16:00:09 hassbian sudo[957]: pam_unix(sudo:session): session opened for user root by pi(uid=0)
Jul 14 16:02:47 hassbian sudo[957]: pam_unix(sudo:session): session closed for user root
Jul 14 16:02:50 hassbian sudo[981]: pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/journalctl -u [email protected]
Jul 14 16:02:50 hassbian sudo[981]: pam_unix(sudo:session): session opened for user root by pi(uid=0)
Jul 14 16:02:50 hassbian sudo[981]: pam_unix(sudo:session): session closed for user root

If there is no such process, why does it run if I type that command in at the prompt.

I found this link … https://superuser.com/questions/1156676/what-causes-systemd-failed-at-step-user-spawning-usr-sbin-opendkim-no-such-p
Looks like it trying to run as root, and I installed it as pi, could that be the issue?

pi@hassbian:~ $ ls -l /usr/local/bin/app*
-rwxr-xr-x 1 root staff 312 Jul 13 23:04 /usr/local/bin/appdaemon
pi@hassbian:~ $

No that’s not it - appdaemon has rights for everyone to execute .,…

Have you setup logging? I would guess that AppDaemon is starting, getting an error then exiting.

Bottom line,

this is what worked for me, not sure if it is right.

[Unit]
Description=AppDaemon
[email protected]
[email protected]
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/appdaemon -c /home/pi/appdaemon/conf

[Install]
WantedBy=multi-user.target

More detail:

I had to change two things.
I changed the user=%i to user=root.
Then I got an error my execstart was not an absolute path, sure enough there was not root /
First when I ran the ‘type appdaemon’ I and saw what I needed, I must have missed the first /.
So then it started. I went back and changed root back to %i and it failed.
What is %i ?
Now the log makes since, the %i was before the execstart, that is why there never was any logs after I changed the user to root, then it made it down enough to find the path error on the execstart command.

The problem is in the name of the service file

user=%i

uses the part of the filename after @ as the user to run as, so

[email protected]

will try to run as the appdaemon user, which probably doesn’t exist.

Rename the file to [email protected], or set user=homeassistant (or even user pi as I don’t think it makes a difference) . Running as root is probably not a good idea for security reasons.

@gpbenton Got it!
Both ways worked.
Just need to work with @aimc on how you all want to do the tutorial for Hassbian.
Thanks

Can I add one more thing under the systemctl config.
I just restarted hass and lost my appdaemon. I saw something where if one of the required stops, you stop. What I not sure is when the required starts how to start you. Just wanted to throw that thought while were in the area. :slight_smile:

Required shouldn’t be necessary, AppFaemon will retry until hass comes back

How long should I have waited?

Well if the requires kills it, forever. Without, AppDaemon should just hang around and reconnect when hass is up., so let’s dump the require.

Sorry miscommunication, I was asking how long before AppDaemon reconnect to hass once hass is back up?
I didn’t time it, but it seems like after about 20 seconds it wasn’t reconnected yet, at least my dashboard didn’t connect .
Next time I will try and bee more scientific . :slight_smile:

The logs should tell the story. HADashboard will stay connected over a hass restart, AppDaemon will reconnect to hass within 5 seconds of it becoming available.

I had to reload my hass for configuration change. The HADashborad dropped as expected, but did not connect. Let me document some of my observations, then I will see if it does it every time.
The log does not show any activity from when hass dropped till I restarted appdaemon. Also I ran status before the restart and it showed appdaemon was running.

2017-07-15 11:55:33.220262 WARNING 'text_sensor' widget is deprecated, please use 'sensor' instead for widget 'mode'
2017-07-15 11:55:34.119485 INFO function [compile_dash] finished in 1510 ms
2017-07-15 11:55:34.471150 INFO Dashboard disconnected
2017-07-15 11:55:38.443345 INFO New dashboard connected: Main Panel
2017-07-15 13:27:44.352984 INFO AppDaemon Version 2.0.4 starting
2017-07-15 13:27:44.353708 INFO Configuration read from: /home/homeassistant/.homeassistant/AppDaemon/conf/appdaemon.yaml
2017-07-15 13:27:44.534526 INFO Got initial state
2017-07-15 13:27:44.543922 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/apps/hello.py
2017-07-15 13:27:44.548469 INFO Loading Object hello_world using class HelloWorld from module hello
2017-07-15 13:27:44.704949 INFO hello_world: Hello from AppDaemon
2017-07-15 13:27:44.707739 INFO hello_world: You are now ready to run Apps!
2017-07-15 13:27:44.708324 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/modes.py
2017-07-15 13:27:44.710166 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/grandfather.py
2017-07-15 13:27:44.712027 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/smart_heat.py
2017-07-15 13:27:44.713931 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/outside_lights.py
2017-07-15 13:27:44.715699 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/momentary_switch.py
2017-07-15 13:27:44.717464 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/battery.py
2017-07-15 13:27:44.719243 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/sensor_notification.py
2017-07-15 13:27:44.721028 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/sensor_notify.py
2017-07-15 13:27:44.722822 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/switch_reset.py
2017-07-15 13:27:44.732205 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/motion_lights.py
2017-07-15 13:27:44.734241 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/dark_day.py
2017-07-15 13:27:44.736097 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/presence.py
2017-07-15 13:27:44.737916 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/motion_notification.py
2017-07-15 13:27:44.739688 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/minimote.py
2017-07-15 13:27:44.742143 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/door_notification.py
2017-07-15 13:27:44.745548 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/hwcheck.py
2017-07-15 13:27:44.748771 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/sound.py
2017-07-15 13:27:44.752073 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/ObjectTracker/objectcontrole.py
2017-07-15 13:27:44.755184 INFO Loading Module: /home/homeassistant/.homeassistant/AppDaemon/conf/example_apps/ObjectTracker/general_app_functions.py
2017-07-15 13:27:44.758200 INFO App initialization complete
2017-07-15 13:27:44.759770 INFO Starting dashboard
2017-07-15 13:27:44.795619 INFO Connected to Home Assistant 0.48.1
2017-07-15 13:28:04.514004 INFO New dashboard connected: Test Panel
2017-07-15 13:28:16.712820 INFO function [compile_dash] finished in 16 ms
2017-07-15 13:28:20.881114 INFO New dashboard connected: Main Panel

Here you can see appdaemon was running but dead (whatever that means)

pi@hassbian:~ $ systemctl status [email protected][email protected] - AppDaemon
   Loaded: loaded (/etc/systemd/system/[email protected]; enabled)
   Active: inactive (dead) since Sat 2017-07-15 13:13:14 UTC; 13min ago
  Process: 4304 ExecStart=/usr/local/bin/appdaemon -c /home/homeassistant/.homeassistant/AppDaemon/conf (code=killed, signal=TERM)
 Main PID: 4304 (code=killed, signal=TERM)
pi@hassbian:~ $ systemctl restart [email protected]
Failed to restart [email protected]: Access denied
pi@hassbian:~ $ sudo systemctl restart [email protected]
pi@hassbian:~ $

Just for future lookers my hass .48.1 and appdamon is 2.0.4.
I can reproduce what I am seeing every time.
restart hass and dashboard does not seem to reconnect.

Something is terminating it - presumably systemctl, when hass stops?

I have a very cut down systemctl file that works fine:

[Unit]
Description=AppDaemon service for Home Assistant

[Service]
ExecStart=/usr/local/bin/appdaemon

[Install]
WantedBy=multi-user.target

You should see seomthing like this when you are restarting hass:

2017-07-15 17:02:38.423161 INFO AppDaemon Version 2.0.4b2 starting
2017-07-15 17:02:38.423584 INFO Configuration read from: /etc/appdaemon/appdaemon.yaml
2017-07-15 17:02:38.589124 INFO Got initial state
2017-07-15 17:02:38.596547 INFO Loading Module: /etc/appdaemon/apps/globals.py
...
2017-07-15 17:02:38.795600 INFO App initialization complete
2017-07-15 17:02:38.796236 INFO Starting dashboard
2017-07-15 17:02:38.828319 INFO Connected to Home Assistant 0.48.1
2017-07-15 17:02:40.084175 WARNING Disconnected from Home Assistant, retrying in 5 seconds
2017-07-15 17:02:45.093866 WARNING Disconnected from Home Assistant, retrying in 5 seconds
2017-07-15 17:02:50.112288 WARNING Disconnected from Home Assistant, retrying in 5 seconds
2017-07-15 17:02:55.118644 WARNING Disconnected from Home Assistant, retrying in 5 seconds
2017-07-15 17:03:00.293360 INFO Got initial state
2017-07-15 17:03:00.311958 INFO Reloading Module: /etc/appdaemon/apps/globals.py
...```

That was it. By having the required in the unit area then systemctl stop appdaemon. if appdaemon starts before hass, no big deal just connect in 5 seconds.
I think we can put the service conf to bed. :slight_smile:

1 Like

Thanks for documenting your struggle - did you go with the cutdown version I posted or something different?