gpbenton / engMQTTClient

MQTT client for Energenie ener314-rt board running on a raspberry Pi
MIT License
21 stars 10 forks source link

Systemd service file, config file and installer. (Issue18,issue3) #19

Closed davet2001 closed 4 years ago

davet2001 commented 4 years ago

This PR provides example systemd service files and a configuration file.

To use it, run

cd service
sudo ./install.sh

Then edit /etc/engmqttclient.conf with relevant config details (broker host, username, password etc)

Fixes #3,#18

gpbenton commented 4 years ago

I have a number of problems with this. First of all, a configuration file needs to be read by the program directly, so that the parameters are not available to be read by some using ps -eaf. Putting a bunch of environment variables in a file and using this in a command line doesn't satisfy this criteria, and is just creating more work. Secondly, it is perfectly possible to create a systemd service file for doing this using the environment and exec line alone. A shell script is not necessary. Thirdly, /usr/bin should be kept for system package files. Locally compiled binaries should be placed in /usr/local/bin.

davet2001 commented 4 years ago

Hi, thanks for the feedback.

If the requirement is definitely that the config settings need to be in a file that is read by the binary, then that is quite a bit more involved. I imagine that means using libconfig or similar.

I would argue that this program is by definition very unlikely to run on multi-user shared servers. The hardware requires it to be run on a raspberry pi. So I don't think there are many people running ps -eaf.
Note that systemctl status reveals whatever is passed on the command line in much the same way.

But I agree that the most correct solution avoids passing credentials on the command line.

I did not realise about /usr/bin vs /usr/local/bin. Point taken.

I'll have a look at the config file route and see how far I get. If it's too involved I'll try a more simple systemd service file without the shell script.

gpbenton commented 4 years ago

I agree the need for a config file is very low priority, which is why I haven't bothered, but setting environment variables does not meet my definition of a config file.

I suggest you concentrate on the systemd file, which should essentially only be two lines

Environment=LD_LIBRARY_PATH setting
Execute=path to bin and parameters

I don't think either prerequisite you have in the file is necessary, and should be removed to speed up system startup. If you find they are necessary, please let me know, as I should really fix the code to make sure they are not.

davet2001 commented 4 years ago

I don’t expect to continue any further work on this.

I have more recently found that I can use a cheap 3pin 433MHz transmitter to control the energenie “green button” sockets.

https://github.com/davet2001/miscellaneous/blob/master/energenie_rpi-rf_433.sh

Once you know the remote code, this can be set up in homeassistant as an RF switch directly: https://www.home-assistant.io/integrations/rpi_rf/

That means I don’t need the ener314-rt, MQTT, or the enermqtt service running.
I find this arrangement to be much more reliable (less to go wrong!) in my use-case where there is only 1-way communication.

Thanks for your work on this in the mean time!

Dave