I have setup HA in a Virtualenv on an Ubuntu 14.04 server. I am trying to modify the example init.d script so the daemon will start on boot but I cannot get HA to start. I am able to start HA manually within the Virtualenv by switching to the hass user and activating the Virtualenv.
# Installation:
# 1) If any commands need to run before executing hass (like loading a
# virutal environment), put them in PRE_EXEC. This command must end with
# a semicolon.
# 2) Set RUN_AS to the username that should be used to execute hass.
# 3) Copy this script to /etc/init.d/
# sudo cp hass-daemon /etc/init.d/hass-daemon
# sudo chmod +x /etc/init.d/hass-daemon
# 4) Register the daemon with Linux
# sudo update-rc.d hass-daemon defaults
# 5) Install this service
# sudo service hass-daemon install
# 6) Restart Machine
Found the log. what i can tell it doesnāt show anyting. Old stuff. Can i delete it and the restart my computer?
Followed this.
I gues my virtual environment should be in /srv/hass/bin/activate? i see the file, activate there.
Tested this. Shouldnāt it say sopped instead of service not running?
kitchen@kitchen:/etc/init.d$ sudo service hass-daemon install
Installing Home Assistant Daemon (hass-daemon)
kitchen@kitchen:/etc/init.d$ sudo service hass-daemon start
Starting serviceā¦
Service started
kitchen@kitchen:/etc/init.d$ sudo service hass-daemon stop
Service not running
kitchen@kitchen:/etc/init.d$
Is this OK? the pid-file in /var/run
-rw-r--r-- 1 hass nogroup 7 Jul 11 23:18 hass.pid
Deleted my home-assistant.log
Rebooted. No new log created.
How does it know what to run? Nothing pointing at /srv/hass/bin/hass
Oh, i thought i did answer your questions.
I am glad you still are trying to help me.
Can i run the commands one by one or shall i type it in alla at once.
I tried to paste it in putty but it looked very strange.
I did install it, sudo service hass-daemon uninstall
Can i try typing it in without install the script?
Or shall i reinstall it first?
BTW:
I found this on the internet.
āSo ive worked it out, for some reason upstart doesnt like using āsourceā so i changed the line from:ā
source bin/activate
to
. bin/activate
āand that works, dont know why though, so would be interested if someone could explain thisā
An answer:
source is a bash built-in command but only a posix āspecialā command.
Upstart runs sh -e when executing the script sections.
Here is what I have in my config. I ended up changing to calling a shell with sudo, and then passing in the commands to start hass.
I had trouble with the redirect, so havenāt changed it to use the FLAGs variable. The > redirect will not work with sudoā¦as in it will end up going into a file owned by root. Bascially, sudo takes the command all the way up to the >. The > then acts like a normal redirect, but under the root user. To redirect to a file owned by hass, you need to use tee.
sudo -u hass -H bash -c "/srv/hass/bin/hass -v --config $CONFIG_DIR --pid-file /var/run/hass.pid --daemon | tee -a $CONFIG_DIR/home-assistant.log"
So essence, this is calling sudo to run a bash shell under the hass user, passing the commands to run hass to the called shell with the pipe to tee for the log file.
I must be doing something wrong because I can get this to start from the command line however when I try to get this to start from boot it wonāt work. I also canāt seem to get the log file to work so I canāt determine what is wrong. I am not using a virtualenv but it should still work. The following is what my config looks like.
PRE_EXEC=""
RUN_AS="mgranger"
PID_FILE="/var/run/hass.pid"
CONFIG_DIR="/home/hass/.homeassistant"
FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --daemon"
REDIRECT="> $CONFIG_DIR/home-assistant.log 2>&1"
start() {
if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then
echo 'Service already running' >&2
return 1
fi
echo 'Starting serviceā¦' >&2
local CMD="$PRE_EXEC hass $FLAGS $REDIRECT;"
# su -c "$CMD" $RUN_AS
sudo -u mgranger -H bash -c "hass $FLAGS | tee -a $CONFIG_DIR/home-assistant.log"
echo 'Service started' >&2 }
Put the absolute path to hass in the sudo command. Also, just to clarify, my other post only had the variables and the start function. The rest of the script was unchanged from the wiki link, and so I didnāt include it in the post.
Did you run service hass-daemon install? I never got any results until I performed that.
I put the absolute path into the sudo command and I get the same result. I can run it from command line but not luck from boot. Like you I only posted my variables and start function. The rest was left unchanged. I did do a service hass-daemon install both in the script above and after I changed to the absolute path. Not really sure what else to try.