Raspbian does not keep files in /run. Therefor the pid directory needs to be created every time after boot. The easies is to put this into the start function.
Sorry, I did not test the patch with all my legacy systems.
I changed the init scripts to be more reliable.
hass executable supports the option --log-file. Using this is much safer and does not lead to problems with permission and overwriting old logfiles. Also I added creating the directory and ownership in the install function. To prevent log file groth I added a logrotate rule.
I moved the update-rc.d command you had in your manual into the install function since you already ad it in the uninstall function. This prevents more copy&paste errors.
I changed the PID file to be located in an extra directory. This way you do not have to to this hack with writing a fake PID file in the install function. Also, I read many users having problems that hass daemon is not starting (see eg. https://community.home-assistant.io/t/autostart-virtualenv-ubuntu-14-04/2120/37) without showing any errors. This is due to a missing PID file or its wrong permissions. By changing as stated and adding a test this problem should not arise any more.
I changes some wording in the manual to make it more understandable.
I found that After=network.target was not robust enough for Auto-discovery to work correctly and find devices on the network. I changed this to After=network-online.target to wait until the network was completely "up" before starting.
* update init.d daemon script to specify HASS_BIN
As per:
* https://home-assistant.io/docs/autostart/init.d/
, coupled with:
* https://home-assistant.io/docs/installation/virtualenv/
It's obvious that the user needs to replace "RUN_AS" with the correct user.
What can be made more clear is to include a "HASS_BIN" shell variable, with a similar instruction to update that if needed.
Note that I opted NOT to change the HASS_BIN to the full path /usr/bin/hass, as the previous revision presumably assumes that the `hass` binary is in the $PATH env for whatever user is running it ... (didn't want to change that).
* Fix name
* Remove unnecessary environment variable setup
The environment variables are not needed and are actually overriding the system PATH variable and were causing trouble in certain circumstances.
* Make the user for the service dynamic
* Cleans up leftover comment
* Refine text to reflect the changes in the service
* Revert change of the users home path
* Updated docs based on user suggestions
Thanks to @NeLLyMerC for the suggestions. Removed the EOF syntax for creating a file. Cleaned up the description of the systemctl commands. Added 'sudo' to the journalctl commands as it will not show the logs if running as an unprived user.
* Update systemd.markdown