Installing HomeBridge (HomeKit bridge to Vera) on Docker Synology

I’ll try to create an updated Dockerfile I’ll post it when it’s done.

Ok, I think I got this working. It’s all based on Tahitihub’s work but I’ve changed it slightly.
So first you install docker GUI from package centre.

Then you log in to Syno via ssh: ssh -p ‘ssh-port’ admin@‘Syno-IP’
Then run: sudo -i (gets you root)
Then make a work directory (mine is /volume1/docker/homebridge)
Then go into that directory and type the following while modifying the second component to fit your install:
(ie: “veraIP”: “10.0.1.5”/“veraIP”: “10.0.1.5” would become “veraIP”: “10.0.1.5”/“veraIP”: “10.0.1.11” as my Vera is on 10.0.1.11. You can also change the PIN here is you wish, but the correct IP is the only change you need to make this work)

[code]cat <Dockerfile
FROM fastfreddi/homebridge-vera:latest

MAINTAINER FastFreddi

USER root

RUN export USER=root && su root
&& sed -i ‘s/“pin”: “987-65-432”/“pin”: “987-65-432”/’ /root/.homebridge/config.json
&& sed -i ‘s/“veraIP”: “10.0.1.5”/“veraIP”: “10.0.1.5”/’ /root/.homebridge/config.json
&& sed -i ‘s/“ignorerooms”: [20,21,22]/“ignorerooms”: []/’ /root/.homebridge/config.json
&& sed -i ‘s/“includesensor”: false/“includesensor”: false/’ /root/.homebridge/config.json
&& sed -i ‘s/“dimmertest”: false/“dimmertest”: false/’ /root/.homebridge/config.json

EXPOSE 51826

CMD [“/root/.homebridge/run.sh”]
EOF
[/code]

Then run:

docker build -t fastfreddi/homebridge-vera-custom .

Then run:

docker run -d -it --net=host -p 51826:51826 --name=Vera-Homebridge fastfreddi/homebridge-vera-custom

Now if everything went well the container should be running. You can check the output in the Docker GUI to make sure. Do not use the Docker GUI to start the container. Use command lines:

docker start Vera-Homebridge
and
docker stop Vera-Homebridge

I suggest creating a startup script as described in my previous post and using task scheduler to deal with reboots.

If you need to modify parameters in the config.json down the road, log into Syno as described above and run

docker exec -it Vera-Homebridge /bin/bash vi /root/.homebridge/config.json

Hopefully this works out.

Here is the startup script to type in Syno ssh root session:

cat <<EOF >/volume1/DockerAuto.sh case $1 in start) /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge ;; stop) /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge ;; *) echo "Usages: $0 [start|stop]" ;; esac EOF chmod 755 /volume1/DockerAuto.sh

Then open Task Scheduler in Synology GUI (DSM 6 and above). (Control Panel > Task Scheduler)
Create a triggered task called: Docker Start
Select user “root”
Choose event: Boot-up
Then in task settings, type: /volume1/DockerAuto.sh start

Create a triggered task called: Docker Stop
Select user “root”
Choose event: Shutdown
Then in task settings, type: /volume1/DockerAuto.sh stop

Enable both tasks and save settings.

Hi FastFreddy,

Thank you very much for this great improvment.

However, can you explain how to schedule start and stop at bootup and shutdown with DSM 5 ?

Regards.

I don’t have DSM 5 to test out, and I don’t recall if the scheduler on DSM 5 supports triggered task. (Just noticed my description says scheduled tasks above, will fix that) If it does not then a script would have to be created. The script will have to contain some parameter telling it to wait until docker is started prior to initializing. I’ll figure something out and post.

Ok I think this should work on DSM5:

ssh as root and then run (your directory paths may differ slightly)

cat <<EOF >/volume1/DockerAuto.sh case $1 in start) /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge ;; stop) /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge ;; *) echo "Usages: $0 [start|stop]" ;; esac EOF chmod 755 /volume1/DockerAuto.sh

then run:

cat <<EOF >/usr/local/etc/rc.d/DockerDSM5.sh start on filesystem and started docker stop on runlevel [06] exec /volume1/DockerAuto.sh EOF chmod 755 /usr/local/etc/rc.d/DockerDSM5.sh

Let me know how this works out.

Hi,

It seems the scheduler on DSM5 doesn’t support triggerded task.

Thank you very much for your help !

[quote=“FastFreddi, post:46, topic:190921”]Ok I think this should work on DSM5:

ssh as root and then run (your directory paths may differ slightly)

cat <<EOF >/volume1/DockerAuto.sh case $1 in start) /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge ;; stop) /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge ;; *) echo "Usages: $0 [start|stop]" ;; esac EOF chmod 755 /volume1/DockerAuto.sh[/quote]

Hi,

When doing this, the file created doesn’t contain $1, and $0 has been replaced by “-ash” :

case in start) /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge ;; stop) /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge ;; *) echo "Usages: -ash [start|stop]" ;; esac

[quote=“FastFreddi, post:46, topic:190921”]then run:

cat <<EOF >/usr/local/etc/rc.d/DockerDSM5.sh start on filesystem and started docker stop on runlevel [06] exec /volume1/DockerAuto.sh EOF chmod 755 /usr/local/etc/rc.d/DockerDSM5.sh

Let me know how this works out.[/quote]

Unfortunately, the script doesn’t work.
Maybe we can add some instructions to create a log file ?

Ok let’s try a different approach

cat <<EOF >/usr/local/etc/rc.d/DockerDSM5.sh start on filesystem and started docker stop on runlevel [06] script /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge end script pre-stop script /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge end script EOF chmod 755 /usr/local/etc/rc.d/DockerDSM5.sh

[quote=“FastFreddi, post:49, topic:190921”]Ok let’s try a different approach

cat <<EOF >/usr/local/etc/rc.d/DockerDSM5.sh start on filesystem and started docker stop on runlevel [06] script /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge end script pre-stop script /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge end script EOF chmod 755 /usr/local/etc/rc.d/DockerDSM5.sh [/quote]

I didn’t have more success with this approach …

It’s very strange because others commands are working well (docker start Vera-Homebridge / docker stop Vera-Homebridge).

It’d be helpfull to have a log result of these commands.

Regards

Ok last one for tonight. Upstart uses folder /etc/init so let’s do this. After ssh as root:

cat <<EOF >/etc/init/DockerDSM5.conf start on filesystem and started docker stop on runlevel [06] script /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge end script EOF chmod 755 /etc/init/DockerDSM5.conf

Then reboot.

The log for upstart is /var/log/upstart/DockerDSM5.log

I finally managed to do it with your help, thank you !

1 - I created the file “DockerAuto.sh” in “/volume1” with the vi editor (because the creation with cat make vanished “$1”, and “$0” has been replaced by “-ash”, as explained before) :

case $1 in start) /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge ;; stop) /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge ;; *) echo "Usages: $0 [start|stop]" ;; esac

2 - I made a “chmod 755 /volume1/DockerAuto.sh”

3 - I created the file “DockerDSM5.conf” in “/etc/init/” with the vi editor

start on filesystem and started docker stop on runlevel [06] exec /volume1/DockerAuto.sh

4 - I made a “chmod 755 etc/init/DockerDSM5.conf”

5 - Reboot

Thanks again !

That’s great! Can you see if printf causes the same replace $ with -ash

printf '%s\n' 'case $1 in' 'start)' ' /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge' ' ;;' 'stop)' ' /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge' ' ;;' '*)' 'echo "Usages: $0 [start|stop]"' ' ;;' 'esac' >/volume1/DockerAuto.sh chmod 755 /volume1/DockerAuto.sh

printf '%s\n' 'start on filesystem and started docker' 'stop on runlevel [06]' 'exec /volume1/DockerAuto.sh' >/etc/init/DockerDSM5.conf chmod 755 /etc/init/DockerDSM5.conf

Hi,

I just find another strange thing : it seems that you have to run the script (or that the container be running) …

cd /volume1/ ./DockerAuto.sh start

… before stopping the NAS, otherwise the container will not launch at next restart.

What do you think about it ?

So the upstart script is not working. The container is restarting because of the Docker restart policy. Let me see if I can fix this.

Ok not sure if this will work on DSM5, doesn’t work on DSM6, but try this:

printf '%s\n' 'case $1 in' '#!/bin/sh' 'start)' ' /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge' ' ;;' 'stop)' ' /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge' ' ;;' '*)' 'echo "Usages: $0 [start|stop]"' ' ;;' 'esac' >/usr/local/etc/rc.d/DockerAuto.sh chmod 755 /usr/local/etc/rc.d/DockerAuto.sh

[quote=“FastFreddi, post:56, topic:190921”]Ok not sure if this will work on DSM5, doesn’t work on DSM6, but try this:

printf '%s\n' 'case $1 in' '#!/bin/sh' 'start)' ' /var/packages/Docker/target/usr/bin/docker start Vera-Homebridge' ' ;;' 'stop)' ' /var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge' ' ;;' '*)' 'echo "Usages: $0 [start|stop]"' ' ;;' 'esac' >/usr/local/etc/rc.d/DockerAuto.sh chmod 755 /usr/local/etc/rc.d/DockerAuto.sh [/quote]

Hi,

No more luck with that one. On another forum, someone advise that you have to follow these instructions :

If you would like to run an application when the system boots up, you have to write a startup script and put it in /usr/local/etc/rc.d/. Following are some rules for the startup script:

  1. It must have the suffix “.sh”. For example, “myprog.sh”.
  2. The permission must be 755.
  3. It must have the options “start” and “stop”. When the system boots up, it will call “myprog.sh start” ; when it shuts down, it will call “myprog.sh stop”.

You can refer to the scripts in /usr/syno/etc/rc.d/. They are script for Synology default services.

FYI, I publish here the script “S99synoreport.sh” :

[code]#!/bin/sh
SYNOREPORT_CMD=/usr/syno/synoreport/synoreport
GET_CMD=/usr/syno/bin/get_section_key_value

SYNOREPORT_CONF=/usr/syno/etc/synoreport.conf

clean_data()
{
LOC=$GET_CMD $SYNOREPORT_CONF global report_location
if [ “x$LOC” != “x” ]; then
$SYNOREPORT_CMD -clean >/dev/null 2>&1
$SYNOREPORT_CMD -data global >/dev/null 2>&1
fi
}

case $1 in
start)
clean_data
exit 0
;;
stop)
exit 0
;;
restart)
clean_data
exit 0
;;
*)
/bin/echo “usage: $0 { start | stop | restart }” >&2
exit 1
;;
esac[/code]

@FastFreddi,

Hi,

Based on the “S99synoreport.sh” script and on your previous attempts, I think I’ve got something that works now :

[code]#!/bin/sh

case $1 in

start)
/var/packages/Docker/target/usr/bin/docker start Vera-Homebridge
;;

stop)
/var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge
;;

restart)
/var/packages/Docker/target/usr/bin/docker stop Vera-Homebridge
;;

*)

/bin/echo “usage: $0 { start | stop | restart }” >&2

;;

esac
[/code]

What do you think about it :

  • is it pertinent to include the “restart” part ?
  • and what about the redirection “>&2” ? Could you tell me how can we see the log of this script ?

Regards

@tahitibub and @FastFreddi and everyone else.

I got this to work on my DS 216+. Thank you for all the information. It works great.

Note:
I had to download the image and not build it on the DS. Being a newb with Docker and Linux commands this thread helped me get it working.

Thanks Again.

Good to hear.
Are you saying the command
“docker build -t fastfreddi/homebridge-vera-custom .”
did not work for you after creating the appropriate Dockerfile? The “.” At the end of that command is important if that was the issue.