[SOLVED] Systemd: Can't add my service for demon

Issues related to applications and software problems
vasyun
Posts: 6
Joined: 2018/06/09 08:30:58

[SOLVED] Systemd: Can't add my service for demon

Post by vasyun » 2018/06/09 08:55:50

Hello All
I'm trying add my service for demon vmpsd, but it not working.

I'am succesfull compiled vmpsd from https://sourceforge.net/projects/vmps/f ... sd/1.4.06/
When i run demon from console

Code: Select all

[root@localhost]# /usr/local/bin/vmpsd -f /usr/local/etc/vlan.db
it working

Code: Select all

[root@localhost]# ps ax|grep vmps
20144 pts/1    S      0:00 /usr/local/bin/vmpsd -f /usr/local/etc/vlan.db
20147 pts/1    S+     0:00 grep --color=auto vmps
Then i created my unit:

Code: Select all

[root@localhost]# cat /etc/systemd/system/vas.service
[Unit]
Description=VAS VMPSD
After=network.target

[Service]
Type=simple
#ExecStart=/usr/local/bin/vmpsd -f /etc/vlan.db
ExecStart=/usr/local/bin/vmpsd -f /usr/local/etc/vlan.db
Restart=always

[Install]
WantedBy=multi-user.target
But service not running.

Code: Select all

[root@localhost]# systemctl  daemon-reload
[root@localhost]# systemctl start vas
[root@localhost]# systemctl status vas
● vas.service - VAS VMPSD
   Loaded: loaded (/etc/systemd/system/vas.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Sat 2018-06-09 11:53:40 MSK; 3s ago
  Process: 20270 ExecStart=/usr/local/bin/vmpsd -f /usr/local/etc/vlan.db (code=exited, status=0/SUCCESS)
 Main PID: 20270 (code=exited, status=0/SUCCESS)

Jun 09 11:53:40 localhos tsystemd[1]: vas.service holdoff time over, scheduling restart.
Jun 09 11:53:40 localhost systemd[1]: start request repeated too quickly for vas.service
Jun 09 11:53:40 localhost systemd[1]: Failed to start VAS VMPSD.
Jun 09 11:53:40 localhost systemd[1]: Unit vas.service entered failed state.
Jun 09 11:53:40 localhost systemd[1]: vas.service failed.
Help me please!

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: Systemd: Can't add my service for demon

Post by hunter86_bg » 2018/06/09 10:54:34

Remove the 'restart' directive, run systemctl daemon-reload and try again.

vasyun
Posts: 6
Joined: 2018/06/09 08:30:58

Re: Systemd: Can't add my service for demon

Post by vasyun » 2018/06/09 11:25:08

Remove the 'restart' directive

Code: Select all

[root@localhost]# systemctl  daemon-reload
[root@localhost]# systemctl start vas
[root@localhost]# systemctl status vas
● vas.service - VAS VMPSD
   Loaded: loaded (/etc/systemd/system/vas.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Sat 2018-06-09 14:00:40 MSK; 21min ago
 Main PID: 21951 (code=exited, status=0/SUCCESS)

Jun 09 14:00:40 localhost systemd[1]: Started VAS VMPSD.
Jun 09 14:00:40 localhost systemd[1]: Starting VAS VMPSD...
demon not started

Code: Select all

[root@localhost]# ps ax |grep vmps
22238 pts/1    S+     0:00 grep --color=auto vmps

mghe
Posts: 766
Joined: 2015/11/24 12:04:43
Location: Katowice, Poland

Re: Systemd: Can't add my service for demon

Post by mghe » 2018/06/09 11:36:22

try to add to service file:


[Service]
...
RestartSec=15


Next:

# systemctl daemon-reload

# reboot

Reboot is important!

User avatar
TrevorH
Site Admin
Posts: 33215
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Systemd: Can't add my service for demon

Post by TrevorH » 2018/06/09 12:44:32

Why? If you do a daemon-reload then a reboot shouldn't be needed.

vasyun: try running setenforce 0 first and then start your daemon up and see if it works then? If it does then you have an selinux access problem but this startup in permissive mode will have created sufficient logs in /var/log/audit/audit.log to allow you to discover what the problem is and fix it.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

vasyun
Posts: 6
Joined: 2018/06/09 08:30:58

Re: Systemd: Can't add my service for demon

Post by vasyun » 2018/06/09 12:54:22

to mghe:
The same thing. Not working.

Code: Select all

root# systemctl daemon-reload
root# reboot

root# uptime
 15:37:43 up 0 min,  1 user,  load average: 0.11, 0.03, 0.01

root# ps ax |grep vmp
 1071 pts/0    S+     0:00 grep --color=auto vmp

root# systemctl status vas
● vas.service - VAS VMPSD
   Loaded: loaded (/etc/systemd/system/vas.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Sat 2018-06-09 15:37:15 MSK; 45s ago
  Process: 730 ExecStart=/usr/local/bin/vmpsd -f /usr/local/etc/vlan.db (code=exited, status=0/SUCCESS)
 Main PID: 730 (code=exited, status=0/SUCCESS)

Jun 09 15:37:15 localhost systemd[1]: Started VAS VMPSD.
Jun 09 15:37:15 localhost systemd[1]: Starting VAS VMPSD...

vasyun
Posts: 6
Joined: 2018/06/09 08:30:58

Re: Systemd: Can't add my service for demon

Post by vasyun » 2018/06/09 12:59:49

to TrevorH:
The same thing. Not working.

Code: Select all

root# setenforce 0
setenforce: SELinux is disabled

root# systemctl status vas
● vas.service - VAS VMPSD
   Loaded: loaded (/etc/systemd/system/vas.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Sat 2018-06-09 15:37:15 MSK; 12min ago
  Process: 730 ExecStart=/usr/local/bin/vmpsd -f /usr/local/etc/vlan.db (code=exited, status=0/SUCCESS)
 Main PID: 730 (code=exited, status=0/SUCCESS)

Jun 09 15:37:15 localhost systemd[1]: Started VAS VMPSD.
Jun 09 15:37:15 localhost systemd[1]: Starting VAS VMPSD...
 
I already disabled SElinux:

Code: Select all

root# cat /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled

# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

User avatar
TrevorH
Site Admin
Posts: 33215
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Systemd: Can't add my service for demon

Post by TrevorH » 2018/06/09 13:08:50

We do not recommend disabling selinux. To re-enable it you will need to edit the config file again and set it to SELINUX=permissive then touch /.autorelabel then reboot and wait while it relabels your entire filesystem. Once that is complete you can edit the file again and change it to enforcing mode and reboot again.

However, the fact that it is disabled rules that out as a cause for your current problem. From

Code: Select all

  Process: 730 ExecStart=/usr/local/bin/vmpsd -f /usr/local/etc/vlan.db (code=exited, status=0/SUCCESS)
  
it would appear that your program is exiting immediately after startup with a code that says nothing was wrong. I would suggest looking at the help pages for the executable and see if it has logging and/or debugging options you can specify and crank those up. Read the log files it producrs to see why it is failing.

Oh, one thing worth checking, when it has "failed" like that, has it actually forked/spawned itself and is actually running? Try pidof vmpsd and see if that reports any pid numbers. If it is running maybe you need to adjust the type of unit file in use.

I suspect it is this. You have Type=simple specified which means systemd is expecting your program to continue to run as the pid that it first started as. From the man page for vmpsd, that says it runs by default as a daemon and you need to specify -d to cause it not to do that. So you can either add -d to your vmpsd command line and keep Type=simple or you can change it to Type=forking which will then expect the started program to spawn a child process and it will monitor that child as the main daemon. You probably have a load of vmpsd processes running. Use man systemd.service to read about Type= possibilities.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mghe
Posts: 766
Joined: 2015/11/24 12:04:43
Location: Katowice, Poland

Re: Systemd: Can't add my service for demon

Post by mghe » 2018/06/09 13:16:42

TrevorH wrote:
2018/06/09 12:44:32
Why? If you do a daemon-reload then a reboot shouldn't be needed.
Yes, service should be run after daemon-reload.

Last time I spend some time to try run my service and tried every things. After reboot service run, magic, that same configuration. There is not first time when I have similar case.

There is something more to do in system to run service or it is bug.


@vasyun


Maybe it can be problem to read/write location.

Try to add to Your service

---------

WorkingDirectory=/usr/local/etc/
User=name_of_user
Group=name_of_group

----------

Add permission user to WorkingDirectory

User avatar
TrevorH
Site Admin
Posts: 33215
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Systemd: Can't add my service for demon

Post by TrevorH » 2018/06/09 13:28:37

Last time I spend some time to try run my service and tried every things. After reboot service run, magic, that same configuration. There is not first time when I have similar case.
If you've ever had to reboot to get systemd changes to be noticed then you did something wrong. Yes, systemd requires a reboot if you update the systemd packages but for changing service files? No.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply