Trying to get smartthings-mqtt-bridge to start on boot

I am trying to get the smartthings-mqtt-bridge to start automatically after reboot.

I created the following in /etc/systemctl/system as smartthings-mqtt-bridge.service

[Unit]
Description=smartthings-mqtt-bridge service
After=mosquitto.service
Before=home-assistant.service

[Service]
Type=simple
User=%i
ExecStart=/usr/local/bin/pm2 start smartthings-mqtt-bridge
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

I copied this from one I have working to start my flic daemon.

It fails to restart after a reboot.
It also fails to start using systemctl manually
sudo systemctl start smartthings-mqtt-bridge.service

Can anyone help with what I am missing?

systemctl shows the following status
pi@flicpi3:~$ sudo systemctl status smartthings-mqtt-bridge.service
â smartthings-mqtt-bridge.service - smartthings-mqtt-bridge service
Loaded: loaded (/etc/systemd/system/smartthings-mqtt-bridge.service; enabled)
Active: activating (auto-restart) since Thu 2017-02-23 03:02:45 HST; 715ms ago
Process: 1904 ExecStart=/usr/local/bin/pm2 start smartthings-mqtt-bridge (code=exited, status=0/SUCCESS)
Main PID: 1904 (code=exited, status=0/SUCCESS)

Running pm2 manually work fine
/usr/local/bin/pm2 start smartthings-mqtt-bridge

/var/log is showing that the service just keep restarting every 3 seconds.

Feb 23 03:31:31 flicpi3 pm2[1427]: âââââââââââââââââââââââââââ¼âââââ¼âââââââ¼âââââââ¼âââââââââ¼ââââââââââ¼âââââââââ¼ââââââ¼âââââââââââ¼âââââââââââ¤
Feb 23 03:31:31 flicpi3 pm2[1427]: â smartthings-mqtt-bridge â 0 â fork â 1439 â online â 0 â 0s â 82% â 6.8 MB â disabled â
Feb 23 03:31:31 flicpi3 pm2[1427]: âââââââââââââââââââââââââââ´âââââ´âââââââ´âââââââ´âââââââââ´ââââââââââ´âââââââââ´ââââââ´âââââââââââ´âââââââââââââââââââââââââââââââââââââ¬âââââ¬âââââââ¬âââââââ¬âââââââââ¬ââââââââââ¬âââââââââ¬ââââââ¬âââââââââââ¬âââââââââââ App name â id â mode â pid â status â restart â uptime â cpu â mem â watching â
Feb 23 03:31:37 flicpi3 pm2[1447]: âââââââââââââââââââââââââââ¼âââââ¼âââââââ¼âââââââ¼âââââââââ¼ââââââââââ¼âââââââââ¼ââââââ¼âââââââââââ¼âââââââââââ¤
Feb 23 03:31:37 flicpi3 pm2[1447]: â smartthings-mqtt-bridge â 0 â fork â 1456 â online â 0 â 0s â 87% â 6.8 MB â disabled â
Feb 23 03:31:37 flicpi3 pm2[1447]: âââââââââââââââââââââââââââ´âââââ´âââââââ´âââââââ´âââââââââ´ââââââââââ´âââââââââ´ââââââ´âââââââââââ´âââââââââââ

@robg I noticed your post about getting appdaemon to autostart and was wondering if you can see what is wrong this this autostart I am trying to get working.

I think the problem is lack of environment but I can’t seem to figure out what is missing. I tried writing a wrapper shell script and sourcing .bashrc and I tried adding some direct environment variable like HOME and PATH.
The logs don’t report any errors but they process just keeps trying to start every 3 seconds as configured in restart. So it looks like the bridge is dying as soon as it starts. It starts find when I start manually using pm2 from the command line.

Hi Smart,

Would love to help, but it’s little out of my league here.Once I work on my autostart hopefully it might give me some insight to your problem. Will advise.

Rob.

Hehe, Sorry about that I thought your post was instructional not a problem getting it to work yourself.

I use Supervisord to manage the bridge. No need PM2 or systemd.

apt-get install supervisor

Create a file smartthings-mqtt-bridge.conf under /etc/supervisor/conf.d/, with the following, and restart supervisor.

[program:smartthings-mqtt-bridge]
command=/usr/local/bin/smartthings-mqtt-bridge
autostart=true
autorestart=true
startretries=999999999999999

@hongtat Not sure I like adding another control method but I decided to try. Are you using this on a raspberry pi?

I followed your steps and restart of supervisor fails

pi@flicpi3:/usr/bin$ sudo systemctl restart supervisor.service
Job for supervisor.service failed. See ‘systemctl status supervisor.service’ and ‘journalctl -xn’ for details.

pi@flicpi3:/usr/bin$ systemctl status supervisor.service
â supervisor.service - LSB: Start/stop supervisor
Loaded: loaded (/etc/init.d/supervisor)
Active: failed (Result: exit-code) since Sun 2017-02-26 02:18:55 HST; 15s ago
Process: 16743 ExecStop=/etc/init.d/supervisor stop (code=exited, status=0/SUCCESS)
Process: 16749 ExecStart=/etc/init.d/supervisor start (code=exited, status=2)

Basically it’s failing the same as my attempt to get the smartthings bridge started with the standard systemctl config. If I take the smartthings config file out of conf.d then supervisor starts fine.

Question did you install supervisor as root? I did not sure if you did.

If you didn’t do you know how to uninstall and re-install as whichever user you installed as?

If you did install as root then I think supervisor doesn’t solve my initial issue.

Yes. I install as root on a RPi 3. Can you reboot to see whether it clears the error?

After reboot it threw an error that helped me find a mistake in my config file. I somehow missed the header line [program:smartthings-mqtt-bridge]. Adding that is works.

I also changed your config a bit to let the bridge run as pi user instead of root. Seems safer that way.

[program:smartthings-mqtt-bridge]
command=/usr/local/bin/smartthings-mqtt-bridge
autostart=true
autorestart=true
startretries=999999999999999
user=pi
environment=HOME="/home/pi",USER=“pi”
directory=/home/pi

Thanks! I guess it is worth keeping supervisor. Much easier to get working.

1 Like

I just tried this today and here was what I found out I could do on my Pi3

pm2 autostart systemd -u pi

In my case, somehow I had smartthings mqtt bridge installed as root so I had to start pm2 with root

sudo pm2 autostart systemd -u root

Then start the bridge:

sudo pm2 start smartthings-mqtt-bridge

Then reboot my PI and it will auto start pm2 and also the bridge.

One more thing I noticed on the first few tries, was that the default timeout = 8 seconds is too short… so it keeps failling, so I modified the “/etc/systemd/system/pm2-root.service” to change the timeout = 30.