I have just found a Node.js app that is run from the command line as follows
This app lets me control and monitor my new heatpump system using mqtt
I run node red on a VM so have plenty of grunt and memory available - is there an easy way to get this app to run in the background on startup of the machine ?
I know this is not strictly a NR question - but doing a google search has led me down a rabbit warren and i do not want to bugger up the machine running my main NR flow
What OS are you running on?
If it is Debian based such as Ubuntu or Raspbian then a simple systemd script should do it.
Sorry - should have said.
yep Ubuntu based in a VM - 18LTS
OK just going through now and trying to set it up as a service with systemd as the user pi
Working through a few issues now
If it just runs as root the "old fashioned easy way" is just to add it to /etc/rc.local - you would need to fully path both the executable and the script name but is an easy fix.
yeah seems to run fine as root - just trying to get it to run as a restricted user (pi) and having problems as it does not seem to understand paths to find the config files - just trying to work through permutations on that before i thrown in the towel and just run it as root
In fact it must be something i am doing/not understanding.
I can run it from the commandline as the pi user from within its own directory (under the home directory for the pi user) - but when i run it as a service it is having problems - must be something to do with paths to pass into the service - just trying to understand how to do that one
When you run from systemd, don't forget that you don't get any of the usual environment variables - like path. However, there are ways to inherit them if you need to. You'll need to look that up I'm afraid, systemd has too many options to just remember
Yeah thanks Julian - i think it is the same boat i am in at the moment - just trying to work through the permutations to make that happen !
OK for anyone else that wants to use this nodejs app (which produces much cleaner output than the other Tuya apps i could find)
The solution i ended up finding was on the openhab forums
To create it as a service
To run tuya-mqtt as a systemd-service, you can create a file:
sudo vi /lib/systemd/system/tuya-mqtt.service
and add the following lines:
After saving the file, you have to run:
sudo systemctl daemon-reload
Now you can start the service:
sudo systemctl start tuya-mqtt.service
Check if the service is runnning properly:
sudo systemctl status tuya-mqtt.service
#1 in this link
Dear OH-community, I found several postings about adding tuya devices to OH. Thanks to @tsightler finally there is a working solution now. Tom rewrote his whole code with some modifications on the underlaying TuyAPI. One of the highlights here is...
Reading time: 7 mins 🕑
Likes: 13 ❤
Do you really mean hom/pi on the execstart line ?
Good Spotting - sorry for the typo - fixed now !
Did you mean to include the space?
If you mean in between /usr/bin/node and then/home/pi etc etc
Don't you need to do
sudo systemctl enable tuya-mqtt.service also if you want the thing to start at reboot
Yep - Exactly - i think that was in the link that i provided also - but good to point out thanks
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.