CentOS 7 Service User at Startup

centos7service

I'm trying to get the noip linux client to run at boot on my system running CentOS 7. To do this i've tried configuring it a service with the following file in /usr/lib/systemd/system/noip.service

[Unit]
Description=Noip
User=root

[Service]
Type=forking
ExecStart=/usr/local/bin/noip2

[Install]
WantedBy=multi-user.target

I ran systemctl enable noip and rebooted the system to test. When I run systemctl status sknoip I get the following:

● noip.service - Noip
   Loaded: loaded (/usr/lib/systemd/system/noip.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2016-12-21 14:03:21 GMT; 1min 13s ago
  Process: 853 ExecStart=/usr/local/bin/noip2 (code=exited, status=0/SUCCESS)
 Main PID: 867 (noip2)
   CGroup: /system.slice/noip.service
           └─867 /usr/local/bin/noip2

Dec 21 14:03:20 server systemd[1]: Starting Noip...
Dec 21 14:03:20 server noip2[867]: v2.1.9 daemon started with NAT enabled
Dec 21 14:03:21 server noip2[867]: Can't gethostbyname for dynupdate.no-ip.com
Dec 21 14:03:21 server noip2[867]: Can't get our visible IP address from ip1.dynupdate.no-ip.com
Dec 21 14:03:21 server systemd[1]: Started Noip.

It doesn't update the noip ip address despite saying it is running, i'm thinking it might have something to do with access to /usr/local/etc/no-ip2.conf but i've tried setting this to 777 as well as setting a user in the service file and setting the owner of this file to that user but no joy.

When I stop and start the service when logged in as root however it starts up fine and does what it should – so i'm guessing there is something permission related to this? Any ideas?

Thanks in advance,

Stuart

Best Answer

You need run service (Noip) after network start.
Try the folowing:

[Unit]
Wants=network-online.target
After=network-online.target

REF:

https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/