voxpupuli / puppet-zabbix

Puppet module for creating and maintaining zabbix components with puppet.

Home Page:https://forge.puppet.com/puppet/zabbix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Agent service needs to require the startup script

baron1405 opened this issue · comments

The agent service does not explicitly require the startup script. This can result in the agent service starting using the wrong systemd service configuration file. The specific case causing the issue is:

Operating system: CentOS 7.7
Zabbix agent version: Default in the module

The zabbix agent RPM installs a systemd service script in /usr/lib/systemd/system. Because the Service['zabbix-agent'] does not require the Systemd::Unit_File['zabbix-agent.service'] in startup.pp, the service configuration file in /usr/lib/systemd/system is used rather than the correct one in /etc/systemd/system. The results in the service not completing its startup and being left in an undefined state (i.e. "starting" according to systemd).

I was able to work around the problem by telling the agent module not to manage the startup script, installing the startup script in my manifest and having the zabbix::agent require the startup script.

class zabbix_agent {
    include systemd
    
    systemd::unit_file { 'zabbix-agent.service':
        source => 'puppet:///modules/zabbix_agent/zabbix-agent.service',
        path   => '/etc/systemd/system',
    }

    class { 'zabbix::agent':
        server                => 'nn.nn.nn.nnn',
        manage_startup_script => false,
        require               => Systemd::Unit_File['zabbix-agent.service'],
    }
}

As far as I can recall, this dependency is automatically managed by Puppet. What version are you using?

I am using Puppet 6.22.1 and puppet-zabbix 9.1.0.

Hey @baron1405 ! Can you take a look at the zabbix::startup class. I believe that can solve your problem (although dunno how obvious/usable is that).

@root-expert thanks for the reply. Yes, I looked at zabbix::startup while investigating this bug. I believe the problem is that where zabbix::agent defines the service resource (line 316) it does not require either the zabbix::startup resource (line 297) or the file resource it creates. Obviously, the startup resource is in an if so the appropriate variable for the require would have to be defined with an undef in the case where managing the startup script is false. I imagine an alternative approach would be for the systemd::unit_file in zabbix::startup (line 47) to perform a notify to the service. Either way, an ordering should be established so that the agent service runs against the module installed systemd service conf (in /etc/systemd/system) rather than the conf file installed by the zabbix-agent package (in /usr/lib/systemd/system).

Note that before arriving at the above workaround where I manage the startup script, I tried using arrow notation to have the service class depend on the systemd unit file resource. It did not work but that could be either due to my clumsiness with Puppet or the relationship not being interpreted when or as expected.

What's your version of puppet/systemd?

@root-expert Versions are:

Puppet: 6.22.1
puppet-zabbix: 9.1.0
CentOS: 7.6
Systemd: 219

Sorry it wasn't very clear, I was asking what's your version of puppet-systemd module 😅

puppet-systemd: 3.0.0