Ad Widget

Collapse

How can I use Zabbix Agent 2 in systemd?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kevimuxx69
    Junior Member
    • Mar 2020
    • 1

    #1

    How can I use Zabbix Agent 2 in systemd?

    Hi,

    I am trying to use a Zabbix Agent 2 compiled in systemd so I can start it as a service and have more control over it. I created the .service but when starting it it returns this error:

    Job for zabbix-agent2.service failed because a timeout was exceeded.
    But really the process has started correctly. The problem with this is that it tries to start it every X time since for the OS it has not started correctly. Do you know if I have done something wrong?

    I leave the .service file that I use (same as the normal agent):

    Code:
    [Unit]
    Description=Zabbix Agent 2
    After=syslog.target
    After=network.target
    
    [Service]
    Environment="CONFFILE=/etc/zabbix/zabbix-agent2/conf/zabbix_agent2.conf"
    EnvironmentFile=-/etc/default/zabbix-agent2
    Type=forking
    Restart=on-failure
    PIDFile=/run/zabbix/zabbix_agentd2.pid
    KillMode=control-group
    ExecStart=/usr/sbin/zabbix_agentd2 -c $CONFFILE
    ExecStop=/bin/kill -SIGTERM $MAINPID
    RestartSec=10s
    User=zabbix
    Group=zabbix
    
    [Install]
    WantedBy=multi-user.target
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    If systemd doesn't realize it started, even though it actually did, that usually means that there is a disagreement between how the daemon behaves and how the service file says the daemon behaves. The first place I would look is at the "Type=" setting. There are many possible options for that setting, and they all depend on how the software actually behaves on startup, whether it truly daemonizes, etc.

    Also, does the PIDFile actually exist after the software starts?

    Comment


    • Kevimuxx69
      Kevimuxx69 commented
      Editing a comment
      Thank you! The PIDFile exists but checking the available types I saw that the selected one would not work
  • Atsushi
    Senior Member
    • Aug 2013
    • 2028

    #3
    The settings used in the package for RHEL are as follows.

    Code:
    [Unit]
    Description=Zabbix Agent 2
    After=syslog.target
    After=network.target
    
    [Service]
    Environment="CONFFILE=/etc/zabbix/zabbix_agent2.conf"
    EnvironmentFile=-/etc/sysconfig/zabbix-agent2
    Type=simple
    Restart=on-failure
    PIDFile=/run/zabbix/zabbix_agent2.pid
    KillMode=control-group
    ExecStart=/usr/sbin/zabbix_agent2 -c $CONFFILE
    ExecStop=/bin/kill -SIGTERM $MAINPID
    RestartSec=10s
    User=zabbix
    Group=zabbix
    
    [Install]
    WantedBy=multi-user.target
    Please try set Type to simple.

    Comment


    • Kevimuxx69
      Kevimuxx69 commented
      Editing a comment
      Thank you very much it worked for me!
Working...