Question

Today I installed Arch Linux on my Raspberry Pi and started to setup fhem. After I installed fhem using yaourt, I customized the fhem configuration, wrote a systemd *.service file and started the service using:

sudo systemctl start fhem
sudo systemctl enable fhem

Then I checked the server status using systemctl status fhem, which gives me the following:

fhem.service - FHEM Perl Server
   Loaded: loaded (/etc/systemd/system/fhem.service; enabled)
   Active: inactive (dead) since Thu 2013-10-17 15:20:42 CEST; 11min ago
  Process: 480 ExecStart=/usr/bin/perl fhem.pl fhem.cfg (code=exited, status=0/SUCCESS)
 Main PID: 480 (code=exited, status=0/SUCCESS)

Oct 17 15:20:41 alarmpi systemd[1]: Started FHEM Perl Server.

So the server seems to run and so i switched to my desktop PC and tried to access the fhem web interface by pointing firefox to 192.168.1.77:8083:

Firefox can't establish a connection to the server at 192.168.1.77:8083 

So I tried to ssh to the Raspberry Pi and that works just fine. Does anybody have an idea why I could not connect to the web interface of fhem? Please find my configuration files below.

/etc/fhem/fhem.cfg

attr global logfile ./log/fhem-%Y-%m.log
attr global modpath .                  # where our FHEM directory is
attr global statefile ./log/fhem.save  # where to save the state of the devices
attr global verbose 3                  # "normal" verbosity (min 1, max 5)

define telnetPort telnet 7072 global   # our TCP/IP port

define WEB FHEMWEB 8083 global

define WEBphone FHEMWEB 8084 global
attr WEBphone stylesheetPrefix smallscreen

define WEBtablet FHEMWEB 8085 global
attr WEBtablet stylesheetPrefix touchpad

# Fake FileLog entry, to access the fhem log from FHEMWEB 
define Logfile FileLog ./log/fhem-%Y-%m.log fakelog

define autocreate autocreate
attr autocreate autosave
attr autocreate device_room %TYPE
attr autocreate filelog ./log/%NAME-%Y.log
attr autocreate weblink
attr autocreate weblink_room Plots

# Disable this to avoid looking for new USB devices on startup
define initialUsbCheck notify global:INITIALIZED usb create 

/etc/systemd/system/fhem.service

[Unit]
Description=FHEM Perl Server
After=syslog.target network.target

[Service]
User=fhem
WorkingDirectory=/opt/fhem
ExecStart=/usr/bin/perl fhem.pl fhem.cfg
Type=simple 

[Install]
WantedBy=multi-user.target

/etc/iptables/iptables.rules

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p udp -m udp --dport 123 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A OUTPUT -p udp -m udp --sport 123 -j ACCEPT
COMMIT
Was it helpful?

Solution

I was able to do what you are trying to achieve using the following systemd service file (main modification beeing the "Type=forking"):

[Unit]                                                                                                 
Description=FHEM Perl Server                                                                           
After=syslog.target network.target                                                                     

[Service]                                                                                              
Type=forking                                                                                                           
User=fhem                                                                                              
WorkingDirectory=/opt/fhem                                                                             
ExecStart=/usr/bin/perl fhem.pl fhem.cfg

Also, as you seem to be using a "fhem" user, ensure this user has sufficient privileges over the required files (I have had to give it write access to the log dir at least)

FYI there is a package in AUR for fhem even thought it lacks this service file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top