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.