Control the user Running FHEM

Begonnen von andyclimb, 21 März 2017, 17:31:36

Vorheriges Thema - Nächstes Thema

andyclimb

I'm trying to write a docker container for FHEM.  In fact I have done so, and it is working well. 

However, I had a lot of trouble getting the user right, and as it stands the user running FHEM must alter the underlying files on their filesystem to match a UID I have chosen, 1000 in order for FHEM to work.    This is not the most ideal situation.  Most docker images, allow you to specify the UID and GID that you want the docker system to run as.  this way it can match your underlying files and permissions.

I am attempting to get this to work with alpine linux as it is more light weight than using a full ubuntu.. however I get this


Can't locate RTypes.pm in @INC (you may need to install the RTypes module) (@INC contains: . /usr/local/lib/perl5/site_perl /usr/local/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at /opt/fhem/fhem.pl line 513.


even though fhem has been started with
exec s6-setuidgid abc perl /opt/fhem/fhem.pl /opt/fhem/fhem.cfg

Which I thought would allow it to be run as user abc.

Is there a way to get fhem to run as a user other than fhem?
AM

rudolfkoenig

Regarding the RTypes error: looks like your fhem.cfg does not contain a line with "attr global modpath <value>".
Regarding the user fhem: FHEM switches to the user fhem, if it is started as root, and there is a user fhem in /etc/passwd.
Else FHEM keeps running as it was started.

andyclimb

Thanks for the very quick reply. 

This has taken me a long time to get to the bottom of.  Might be worth adding to the documentation.    By default fhem expects to be launched from its home directory.  This has caused me so much pain...  It was you hint about the modpath that made me think.  now I just cd into the directory before starting the script and it works fine.  The weird thing is getting two different errors for the two different config files in the fresh install. 

Now I'm onto installing all the perl modules and stuff. 

How hard would it be to have some extra command line variables passed to fhem.  such as specify run user, and modpath...
AM

rudolfkoenig

You just have to convince me, that this would be much harder for you. :)

andyclimb

A fair point!  I've absolutely no experience with perl!  and any attempts i've ever made to write anything in fhem using perl has always turned into a complete disaster.  I tried to write my own module to support an ESP8266 device i've written and after several days I just gave up!  I've been teaching myself c++ and javascript over the last 2 years, but perl i've not got near.  i would not even know where to start.

I've got this working nicely.  The trick was not having a fhem user, so thank you..

I guess maybe a small explanation of this on the 'running fhem' section would be easiest.  ie..  if you have a fhem user on the system it will run under that, otherwise whoever starts it.  that was mostly what I needed.  And also a comment about the mod path, and taking the directory when the command is executed from, not where fhem.pl resides...   So more documentation changes than programming. ?
AM

Prof. Dr. Peter Henning

Hm, since I guess that you have at least some reading capabilities of German: have a look at https://wiki.selfhtml.org/wiki/Perl

LG

pah

rudolfkoenig

Zitat...but perl i've not got near.  i would not even know where to start.
This problem can be solved with "outside FHEM" work by modifying the standard fhem.cfg, changing /etc/passwd, starting FHEM in the right directory, etc. I was referring to this as an alternative to changing fhem.pl

I added the setuid stuff to the fhem intro.
The modpath is described adequately IMHO.