Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix agent not restarting when needed #77

Merged
merged 1 commit into from
Mar 28, 2018

Conversation

edusperoni
Copy link
Contributor

On the first run, when the service is already started by the package installation, the formula fails to restart the agent saying that agent is already running and enabled.

This approach is similar to what apache-formula uses and it forces the agent to be restarted whenever the config changes.
https://github.com/saltstack-formulas/apache-formula/blob/master/apache/init.sls#L38

@landergate
Copy link
Member

@edusperoni
Looks fair. Thanks! =)

@landergate landergate merged commit b04ab47 into saltstack-formulas:master Mar 28, 2018
@hatifnatt
Copy link
Collaborator

I think reason why service is not restarted - because there is single ID with 2 modules pkg.installed and service.sunning if service module will be on separate ID this problem does not appear. I just tested it

agent/init.sls

zabbix-agent:
  pkg.installed:
    - pkgs:
      {%- for name in zabbix.agent.pkgs %}
      - {{ name }}
      {%- endfor %}
    {%- if zabbix.agent.version is defined %}
    - version: {{ zabbix.agent.version }}
    {%- endif %}

zabbix-agent_service:
  service.running:
    - name: {{ zabbix.agent.service }}
    - enable: True
    - require:
      - pkg: zabbix-agent
      - file: zabbix-agent-logdir
      - file: zabbix-agent-piddir

agent/conf.sls

{{ zabbix.agent.config }}:
  file.managed:
    - source: {{ files_switch('zabbix',
                              ['/etc/zabbix/zabbix_agentd.conf',
                               '/etc/zabbix/zabbix_agentd.conf.jinja']) }}
    - template: jinja
    - require:
      - pkg: zabbix-agent
      - user: zabbix_user
    - watch_in:
      - service: zabbix-agent_service

Output:

----------
          ID: zabbix-agent_service
    Function: service.running
        Name: zabbix-agent
      Result: True
     Comment: Service restarted
     Started: 19:29:26.471353
    Duration: 34.942 ms
     Changes:
              ----------
              zabbix-agent:
                  True

@hatifnatt
Copy link
Collaborator

@edusperoni can you please be more specific at what circumstances you have problem when agent is not restarted? I have installed bunch of VMs with this formula before your PR and without ID splitting which I described above (which is actually have no effect at all as I found after testing) and I never have issue that I need to restart agent once more after single formula run. But all my VMs are Debian, may be it's something RedHat specific.
So I decided to check is agent restarted without your changes, I ran tests several times, and does not faced issue when agent is running with default config which came with package. Also I tested same thing in zabbix.server state currently it uses same logic as zabbix.agent before your changes and also no problems with restart. Btw. server state does not reporting restart

----------
          ID: zabbix-server
    Function: service.running
      Result: True
     Comment: Service zabbix-server is already enabled, and is running
     Started: 00:15:57.323489
    Duration: 100.205 ms
     Changes:

but it's running with right config generated from template.
In conclusion, I am not convinced of the need for these changes.

Speaking of apache-formula, as I can see they using module states because they want both restart and reload and this two 'hooks' possibly best way to achieve this.

@edusperoni
Copy link
Contributor Author

All my machines are also Debian. I'll spin one up tomorrow at work and post the results.

The ID splitting is probably a better solution to this.

Try purging the zabbix agent and running it. When you install the package, it already starts and enables the daemon with the base configuration. Salt then edits the config and updates the file. When checking the service state, salt says the service is already running and enabled and doesn't restart the service. Any change after the first one triggers the restart.

I found myself actually having to call salt minion service.restart zabbix-agent every time I deployed the agent on a new machine.

@hatifnatt
Copy link
Collaborator

Try purging the zabbix agent and running it.

That is exactly how I'm running test.
What version of Debian are you using? What is zabbix.version_repo? Do you using official Zabbix repository?

I'm testing on Debian 9, version_repo - 3.0, using official repository.

The ID splitting is probably a better solution to this.

Unfortunately I misled you, according to my new tests ID splitting have no effect. My agent is always restarted, and my server is always is already enabled, and is running without restart but with correct config.

@edusperoni
Copy link
Contributor Author

I'm using version_repo 3.4

Also, are you absolutely sure it's running with the correct config? The default config is enough to get the agent running and answering requests, but if you add, say a custom parameter or set the Server directive to any server other than the Zabbix Server, it should throw an error when querying the agent.

@hatifnatt
Copy link
Collaborator

I'm sure agent running correct config, by default Server parameter is 127.0.0.1 and there is on server at 127.0.0.1 which agent can connect.
I tested again with version_repo 3.4

 30377:20180329:123557.559 Starting Zabbix Agent [Zabbix server]. Zabbix 3.4.7 (revision 77720).
 30377:20180329:123557.559 **** Enabled features ****
 30377:20180329:123557.559 IPv6 support:          YES
 30377:20180329:123557.559 TLS support:           YES
 30377:20180329:123557.559 **************************
 30377:20180329:123557.559 using configuration file: /etc/zabbix/zabbix_agentd.conf
 30377:20180329:123557.560 agent #0 started [main process]
 30381:20180329:123557.561 agent #4 started [listener #3]
 30380:20180329:123557.563 agent #3 started [listener #2]
 30382:20180329:123557.563 agent #5 started [active checks #1]
 30382:20180329:123557.565 active check configuration update from [127.0.0.1:10051] started to fail (cannot connect to [[127.0.0.1]:10051]: [111] Connection refused)
 30378:20180329:123557.565 agent #1 started [collector]
 30379:20180329:123557.565 agent #2 started [listener #1]
 30377:20180329:123559.248 Got signal [signal:15(SIGTERM),sender_pid:30453,sender_uid:0,reason:0]. Exiting ...
 30377:20180329:123559.251 Zabbix Agent stopped. Zabbix 3.4.7 (revision 77720).
 30458:20180329:123559.258 Starting Zabbix Agent [agent.hostname.here]. Zabbix 3.4.7 (revision 77720).
 30458:20180329:123559.259 **** Enabled features ****
 30458:20180329:123559.259 IPv6 support:          YES
 30458:20180329:123559.259 TLS support:           YES
 30458:20180329:123559.259 **************************
 30458:20180329:123559.259 using configuration file: /etc/zabbix/zabbix_agentd.conf
 30458:20180329:123559.259 agent #0 started [main process]
 30464:20180329:123559.261 agent #5 started [active checks #1]
 30463:20180329:123559.263 agent #4 started [listener #3]
 30460:20180329:123559.263 agent #1 started [collector]
 30461:20180329:123559.264 agent #2 started [listener #1]
 30462:20180329:123559.265 agent #3 started [listener #2]

As you can see agent successfully restated with correct config.
I ran test on 3 VMs 1 Debian 8, 2 Debian 9 - every time log looks like above, i.e. agent successfully restarted.
We does not checked one important thing - what is your SaltStack version?

± salt --versions-report
Salt Version:
           Salt: 2017.7.4
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.5.3
      docker-py: Not Installed
          gitdb: 2.0.0
      gitpython: 2.1.1
          ioflo: Not Installed
         Jinja2: 2.9.4
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: 1.3.7
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.13 (default, Nov 24 2017, 17:33:09)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: 2.0.1
        timelib: Not Installed
        Tornado: 4.4.3
            ZMQ: 4.2.1
System Versions:
           dist: debian 9.3
         locale: UTF-8
        machine: x86_64
        release: 4.9.0-6-amd64
         system: Linux
        version: debian 9.3

But I'm started to use this formula when I was at salt 2016.11 and also have no issues with restart.

@edusperoni
Copy link
Contributor Author

edusperoni commented Mar 29, 2018

Here's my test:

----------
          ID: zabbix_group
    Function: group.present
        Name: zabbix
      Result: True
     Comment: New group zabbix created
     Started: 08:11:09.929509
    Duration: 134.938 ms
     Changes:
              ----------
              gid:
                  998
              members:
              name:
                  zabbix
              passwd:
                  x
----------
          ID: zabbix_user
    Function: user.present
        Name: zabbix
      Result: True
     Comment: New user zabbix created
     Started: 08:11:10.067813
    Duration: 316.839 ms
     Changes:
              ----------
              fullname:
              gid:
                  998
              groups:
                  - zabbix
              home:
              homephone:
              name:
                  zabbix
              passwd:
                  x
              roomnumber:
              shell:
                  /bin/false
              uid:
                  998
              workphone:
----------
          ID: zabbix-agent-logdir
    Function: file.directory
        Name: /var/log/zabbix
      Result: True
     Comment: Directory /var/log/zabbix updated
     Started: 08:11:10.385712
    Duration: 3.983 ms
     Changes:
              ----------
              /var/log/zabbix:
                  New Dir
----------
          ID: zabbix-agent-piddir
    Function: file.directory
        Name: /var/run/zabbix
      Result: True
     Comment: Directory /var/run/zabbix updated
     Started: 08:11:10.389898
    Duration: 2.118 ms
     Changes:
              ----------
              /var/run/zabbix:
                  New Dir
----------
          ID: zabbix_agent_repo_gpg_file
    Function: file.managed
        Name: /var/tmp/zabbix-official-repo.gpg
      Result: True
     Comment: File /var/tmp/zabbix-official-repo.gpg updated
     Started: 08:11:10.398713
    Duration: 2522.501 ms
     Changes:
              ----------
              diff:
                  New file
              mode:
                  0644
----------
          ID: zabbix_agent_repo_add_gpg
    Function: cmd.wait
        Name: /usr/bin/apt-key add /var/tmp/zabbix-official-repo.gpg
      Result: True
     Comment: Command "/usr/bin/apt-key add /var/tmp/zabbix-official-repo.gpg" run
     Started: 08:11:12.923246
    Duration: 3483.999 ms
     Changes:
              ----------
              pid:
                  30993
              retcode:
                  0
              stderr:
                  Warning: apt-key output should not be parsed (stdout is not a terminal)
              stdout:
                  OK
----------
          ID: zabbix_agent_repo
    Function: pkgrepo.managed
        Name: deb http://repo.zabbix.com/zabbix/3.4/debian stretch main
      Result: True
     Comment: Configured package repo 'deb http://repo.zabbix.com/zabbix/3.4/debian stretch main'
     Started: 08:11:16.410743
    Duration: 5840.22 ms
     Changes:
              ----------
              repo:
                  deb http://repo.zabbix.com/zabbix/3.4/debian stretch main
----------
          ID: zabbix-agent
    Function: pkg.installed
      Result: True
     Comment: 2 targeted packages were installed/updated.
     Started: 08:11:22.253927
    Duration: 3914.865 ms
     Changes:
              ----------
              zabbix-agent:
                  ----------
                  new:
                      1:3.4.7-1+stretch
                  old:
              zabbix-sender:
                  ----------
                  new:
                      1:3.4.7-1+stretch
                  old:
----------
          ID: /etc/zabbix/zabbix_agentd.conf
    Function: file.managed
      Result: True
     Comment: File /etc/zabbix/zabbix_agentd.conf updated
     Started: 08:11:28.152241
    Duration: 498.593 ms
     Changes:
              ----------
              diff:
                  ---
                  +++
                  @@ -1,3 +1,4 @@
                  +# Managed by saltstack. Do not edit this file.
                   # This is a configuration file for Zabbix agent daemon (Unix)
                   # To get more information about Zabbix, visit http://www.zabbix.com

                  @@ -71,6 +72,7 @@
                   # Mandatory: no
                   # Default:
                   # EnableRemoteCommands=0
                  +EnableRemoteCommands=1

                   ### Option: LogRemoteCommands
                   #    Enable logging of executed shell commands as warnings.
                  @@ -80,21 +82,20 @@
                   # Mandatory: no
                   # Default:
                   # LogRemoteCommands=0
                  +LogRemoteCommands=1

                   ##### Passive checks related

                   ### Option: Server
                  -#    List of comma delimited IP addresses, optionally in CIDR notation, or hostnames of Zabbix servers.
                  +#    List of comma delimited IP addresses (or hostnames) of Zabbix servers.
                   #    Incoming connections will be accepted only from the hosts listed here.
                  -#    If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally and '::/0' will allow any IPv4 or IPv6 address.
                  -#    '0.0.0.0/0' can be used to allow any IPv4 address.
                  -#    Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.domain
                  +#    If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally.
                   #
                   # Mandatory: no
                   # Default:
                   # Server=

                  -Server=127.0.0.1
                  +Server=**redacted**

                   ### Option: ListenPort
                   #    Agent will listen on this port for connections from the server.
                  @@ -103,6 +104,7 @@
                   # Range: 1024-32767
                   # Default:
                   # ListenPort=10050
                  +ListenPort=10050

                   ### Option: ListenIP
                   #    List of comma delimited IP addresses that the agent should listen on.
                  @@ -111,6 +113,7 @@
                   # Mandatory: no
                   # Default:
                   # ListenIP=0.0.0.0
                  +ListenIP=0.0.0.0,::

                   ### Option: StartAgents
                   #    Number of pre-forked instances of zabbix_agentd that process passive checks.
                  @@ -120,6 +123,7 @@
                   # Range: 0-100
                   # Default:
                   # StartAgents=3
                  +StartAgents=7

                   ##### Active checks related

                  @@ -135,7 +139,7 @@
                   # Default:
                   # ServerActive=

                  -ServerActive=127.0.0.1
                  +ServerActive=**redacted**

                   ### Option: Hostname
                   #    Unique, case sensitive hostname.
                  @@ -146,7 +150,7 @@
                   # Default:
                   # Hostname=

                  -Hostname=Zabbix server
                  +Hostname=**redacted**

                   ### Option: HostnameItem
                   #    Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.
                  @@ -166,6 +170,7 @@
                   # Range: 0-255 characters
                   # Default:
                   # HostMetadata=
                  +HostMetadata=**redacted**

                   ### Option: HostMetadataItem
                   #    Optional parameter that defines an item used for getting host metadata.
                  @@ -193,6 +198,7 @@
                   # Range: 1-3600
                   # Default:
                   # BufferSend=5
                  +BufferSend=10

                   ### Option: BufferSize
                   #    Maximum number of values in a memory buffer. The agent will send
                  @@ -202,6 +208,7 @@
                   # Range: 2-65535
                   # Default:
                   # BufferSize=100
                  +BufferSize=1000

                   ### Option: MaxLinesPerSecond
                   #    Maximum number of new lines the agent will send per second to Zabbix Server
                  @@ -236,6 +243,7 @@
                   # Range: 1-30
                   # Default:
                   # Timeout=3
                  +Timeout=20

                   ### Option: AllowRoot
                   #    Allow the agent to run as 'root'. If disabled and the agent is started by 'root', the agent
                  @@ -264,11 +272,7 @@
                   # Default:
                   # Include=

                  -Include=/etc/zabbix/zabbix_agentd.d/*.conf
                  -
                  -# Include=/usr/local/etc/zabbix_agentd.userparams.conf
                  -# Include=/usr/local/etc/zabbix_agentd.conf.d/
                  -# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf
                  +Include=/etc/zabbix/zabbix_agentd.d/

                   ####### USER-DEFINED MONITORED PARAMETERS #######

                  @@ -293,6 +297,7 @@
                   # Mandatory: no
                   # Default:
                   # UserParameter=
                  +UserParameter=proc.num.pidfile[*],[ -f "$1" ] && { ps acx -o pid | grep "^\s*$(cat "$1")\b" | wc -l ; } || { echo "0" ; }

                   ####### LOADABLE MODULES #######

                  @@ -394,3 +399,4 @@
                   # Mandatory: no
                   # Default:
                   # TLSPSKFile=
                  +
----------
          ID: zabbix-agent
    Function: service.running
      Result: True
     Comment: Service zabbix-agent has been enabled, and is in the desired state
     Started: 08:11:28.656697
    Duration: 1007.97 ms
     Changes:
              ----------
              zabbix-agent:
                  True

And this is the agent log:

cat /var/log/zabbix/zabbix_agentd.log
 31929:20180329:081125.204 Starting Zabbix Agent [Zabbix server]. Zabbix 3.4.7 (revision 77720).
 31929:20180329:081125.205 **** Enabled features ****
 31929:20180329:081125.205 IPv6 support:          YES
 31929:20180329:081125.205 TLS support:           YES
 31929:20180329:081125.205 **************************
 31929:20180329:081125.205 using configuration file: /etc/zabbix/zabbix_agentd.conf
 31929:20180329:081125.209 agent #0 started [main process]
 31932:20180329:081125.220 agent #2 started [listener #1]
 31933:20180329:081125.223 agent #3 started [listener #2]
 31930:20180329:081125.226 agent #1 started [collector]
 31936:20180329:081125.227 agent #5 started [active checks #1]
 31935:20180329:081125.230 agent #4 started [listener #3]
 31936:20180329:081125.356 active check configuration update from [127.0.0.1:10051] started to fail (cannot connect to [[127.0.0.1]:10051]: [111] Connection refused)

And the versions:

salt --versions-report
Salt Version:
           Salt: 2017.7.4

Dependency Versions:
           cffi: 0.8.6
       cherrypy: 3.5.0
       dateutil: 2.2
      docker-py: Not Installed
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
         Jinja2: 2.9.4
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.2
   mysql-python: 1.2.3
      pycparser: 2.10
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.9 (default, Jun 29 2016, 13:08:31)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.4.0
           RAET: Not Installed
          smmap: 0.8.2
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: debian 8.10
         locale: UTF-8
        machine: x86_64
        release: 3.16.0-4-amd64
         system: Linux
        version: debian 8.10

top file:

  'minion':
    - zabbix.agent.repo
    - zabbix.agent
    - zabbix.agent.conf

agent log after a manual restart:

 31929:20180329:081125.204 Starting Zabbix Agent [Zabbix server]. Zabbix 3.4.7 (revision 77720).
 31929:20180329:081125.205 **** Enabled features ****
 31929:20180329:081125.205 IPv6 support:          YES
 31929:20180329:081125.205 TLS support:           YES
 31929:20180329:081125.205 **************************
 31929:20180329:081125.205 using configuration file: /etc/zabbix/zabbix_agentd.conf
 31929:20180329:081125.209 agent #0 started [main process]
 31932:20180329:081125.220 agent #2 started [listener #1]
 31933:20180329:081125.223 agent #3 started [listener #2]
 31930:20180329:081125.226 agent #1 started [collector]
 31936:20180329:081125.227 agent #5 started [active checks #1]
 31935:20180329:081125.230 agent #4 started [listener #3]
 31936:20180329:081125.356 active check configuration update from [127.0.0.1:10051] started to fail (cannot connect to [[127.0.0.1]:10051]: [111] Connection refused)
 31929:20180329:081819.422 Got signal [signal:15(SIGTERM),sender_pid:32050,sender_uid:0,reason:0]. Exiting ...
 31929:20180329:081819.459 Zabbix Agent stopped. Zabbix 3.4.7 (revision 77720).
 32056:20180329:081819.521 Starting Zabbix Agent [REDACTED]. Zabbix 3.4.7 (revision 77720).
 32056:20180329:081819.522 **** Enabled features ****
 32056:20180329:081819.522 IPv6 support:          YES
 32056:20180329:081819.522 TLS support:           YES
 32056:20180329:081819.522 **************************
 32056:20180329:081819.522 using configuration file: /etc/zabbix/zabbix_agentd.conf
 32056:20180329:081819.522 agent #0 started [main process]
 32058:20180329:081819.527 agent #2 started [listener #1]
 32059:20180329:081819.531 agent #3 started [listener #2]
 32057:20180329:081819.535 agent #1 started [collector]
 32060:20180329:081819.536 agent #4 started [listener #3]
 32062:20180329:081819.539 agent #6 started [listener #5]
 32061:20180329:081819.545 agent #5 started [listener #4]
 32063:20180329:081819.547 agent #7 started [listener #6]
 32064:20180329:081819.551 agent #8 started [listener #7]
 32065:20180329:081819.556 agent #9 started [active checks #1]
 32065:20180329:081819.945 no active checks on server [REDACTED:10051]: host [REDACTED] not found

That last error is correct, since the agent will auto register based on hostmetada.

@hatifnatt
Copy link
Collaborator

hatifnatt commented Mar 29, 2018

That's odd...
Do you running with regular salt command or with salt-ssh?
I suppose you are running something like salt 'minion*' state.highstate?
Can you please provide output of salt 'minion*' state.show_highstate --out=yaml

Also you don't need zabbix.agent in top file

  'minion':
    - zabbix.agent.repo
    - zabbix.agent.conf

is enough, although I tested with zabbix.agent in top file, and it have no negative effect.

@edusperoni
Copy link
Contributor Author

Regular salt, here's the show_highstate:

  zabbix-agent:
    __env__: base
    __sls__: zabbix.agent
    pkg:
    - pkgs:
      - zabbix-agent
      - zabbix-sender
    - installed
    - order: 10062
    service:
    - name: zabbix-agent
    - enable: true
    - require:
      - pkg: zabbix-agent
      - file: zabbix-agent-logdir
      - file: zabbix-agent-piddir
    - running
    - order: 10063
  zabbix-agent-logdir:
    __env__: base
    __sls__: zabbix.agent
    file:
    - name: /var/log/zabbix
    - user: zabbix
    - group: zabbix
    - dirmode: 755
    - directory
    - order: 10060
  zabbix-agent-piddir:
    __env__: base
    __sls__: zabbix.agent
    file:
    - name: /var/run/zabbix
    - user: zabbix
    - group: zabbix
    - dirmode: 750
    - directory
    - order: 10061
  zabbix_agent_repo:
    __env__: base
    __sls__: zabbix.agent.repo
    pkgrepo:
    - name: deb http://repo.zabbix.com/zabbix/3.4/debian stretch main
    - file: /etc/apt/sources.list.d/zabbix.list
    - require:
      - cmd: zabbix_agent_repo_add_gpg
    - managed
    - order: 10064
  zabbix_agent_repo_add_gpg:
    __env__: base
    __sls__: zabbix.agent.repo
    cmd:
    - name: /usr/bin/apt-key add /var/tmp/zabbix-official-repo.gpg
    - watch:
      - file: zabbix_agent_repo_gpg_file
    - wait
    - order: 10065
  zabbix_agent_repo_gpg_file:
    __env__: base
    __sls__: zabbix.agent.repo
    file:
    - name: /var/tmp/zabbix-official-repo.gpg
    - source:
      - salt://zabbix/files/bi.cpd.ufsm.br/tmp/zabbix-official-repo.gpg
      - salt://zabbix/files/Debian/tmp/zabbix-official-repo.gpg
      - salt://zabbix/files/default/tmp/zabbix-official-repo.gpg
    - managed
    - order: 10066
  zabbix_group:
    __env__: base
    __sls__: zabbix.users
    group:
    - name: zabbix
    - system: true
    - present
    - order: 10059
  zabbix_user:
    __env__: base
    __sls__: zabbix.users
    user:
    - name: zabbix
    - gid_from_name: true
    - groups: []
    - createhome: false
    - shell: /bin/false
    - system: true
    - require:
      - group: zabbix_group
    - present
    - order: 10058

@hatifnatt
Copy link
Collaborator

Why there is nothing like:

  /etc/zabbix/zabbix_agentd.conf:
    __env__: dev
    __sls__: zabbix.agent.conf
    file:
    - source:
      - salt://zabbix/files/Debian/etc/zabbix/zabbix_agentd.conf
      - salt://zabbix/files/Debian/etc/zabbix/zabbix_agentd.conf.jinja
      - salt://zabbix/files/default/etc/zabbix/zabbix_agentd.conf
      - salt://zabbix/files/default/etc/zabbix/zabbix_agentd.conf.jinja
    - template: jinja
    - require:
      - pkg: zabbix-agent
      - user: zabbix-formula_zabbix_user
    - watch_in:
      - service: zabbix-agent
    - managed
    - order: 10014

Which actually have

    - watch_in:
      - service: zabbix-agent

requisite.

@edusperoni
Copy link
Contributor Author

That's actually my bad. I accidentally left it out:

  /etc/zabbix/zabbix_agentd.conf:
    __env__: base
    __sls__: zabbix.agent.conf
    file:
    - source:
      - salt://zabbix/files/bi.cpd.ufsm.br/etc/zabbix/zabbix_agentd.conf
      - salt://zabbix/files/bi.cpd.ufsm.br/etc/zabbix/zabbix_agentd.conf.jinja
      - salt://zabbix/files/Debian/etc/zabbix/zabbix_agentd.conf
      - salt://zabbix/files/Debian/etc/zabbix/zabbix_agentd.conf.jinja
      - salt://zabbix/files/default/etc/zabbix/zabbix_agentd.conf
      - salt://zabbix/files/default/etc/zabbix/zabbix_agentd.conf.jinja
    - template: jinja
    - require:
      - pkg: zabbix-agent
      - user: zabbix_user
    - watch_in:
      - service: zabbix-agent
    - managed
    - order: 10067

@hatifnatt
Copy link
Collaborator

I can't see any problem here, but there is must be a reason. I have no problems with restart, I think all other people who use this formula are not have this problem too, otherwise the problem would have been noticed long ago.
Have you tried separate ID's? There is small chance it might help.

@hatifnatt
Copy link
Collaborator

@edusperoni hi again, can you please test this update https://github.com/hatifnatt/zabbix-formula/tree/separate_id_for_service in your environment? There is separate id for service.running state and some other changes.

@edusperoni
Copy link
Contributor Author

Well, this is weird, It's working on my test machine even without separate IDs. I've since upgraded to 2018.3, but when I had this problem for a while, probably since at least 2017.7, and it was only with this formula. When I opened this request, I was at 2017.7.4.

I couldn't find anything on the changelogs regarding the service. I'll try running the formula on another machine to confirm.

@edusperoni
Copy link
Contributor Author

spoke too son, it failed on the other machine

@hatifnatt
Copy link
Collaborator

Thanks for information! I'm (unfortunately =) ) still on 2017.7.4 and as a mentioned before, I never have this issue with or without separate ID's. May be now when you have machine where formula not fully functional and where it's running fine you can find the cause?

@edusperoni
Copy link
Contributor Author

Ok, this may be a bug with salt. Please try this:

Run the formula/install zabbix agent
systemctl disable zabbix-agent && apt-get purge zabbix-agent -y
Run the formula again

Does the service restart? If I just purge the agent without disabling it, it restarts normally, but if I disable it first (and on first install), it doesn't restart on it's own

@hatifnatt
Copy link
Collaborator

Yes I can confirm, if service disabled before purge, and then installed again via formula, restart is not preformed. Fortunately I have clean machine where zabbix-agent have never installed. So I also can confirm that on first install service is not restarted. All my previous test done on machines where zabbix-agent have been already installed before and then removed without disabling. Thank you for your time! I think this problem can be considered as bug in Salt but I never faced with it before.

@edusperoni
Copy link
Contributor Author

After further investigation, zabbix does not enable it's services, but starts them. That's what's causing this issue. I've opened an Issue in the salt repo

@OrangeDog
Copy link

OrangeDog commented Jul 19, 2022

This breaks if Salt is using the new module.run syntax instead of the deprecated version.

Edit:
My bad, I thought this was a recent change. Plus I'd already filed this issue: #102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants