Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-9626

pidfile contains carriage return '\r' which fails to stop zabbix-agent

XMLWordPrintable

    • Icon: Incident report Incident report
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.2.10rc1, 2.4.6rc1
    • 2.4.5
    • Agent (G)
    • RHEL6.6, installed zabbix-agent from official Zabbix repository

      When stopping the zabbix-agent on RHEL6.6 this fails, which causes a restart also to fail.

      for example:

      service zabbix-agent stop
      Shutting down Zabbix agent:                                [FAILED]
      

      When looking at the init script (/etc/init.d/zabbix-agent) all the zabbix-agentd.conf is correctly parsed, the pidfile is present at the configured location and is read/writable by the zabbix user.
      When debugging the init script, the variable $pidfile contains a carriage return '\r' at the end, which causes the killproc unable to locate the actual pidfile:

      /etc/zabbix# pidfile=$(grep -e "^PidFile=.*$" /etc/zabbix/zabbix_agentd.conf | cut -d= -f2)
      /etc/zabbix# echo $pidfile
      /var/run/zabbix/zabbix_agentd.pid
      /etc/zabbix# cat $pidfile
      : File or folder doesn't existgentd.pid
      

      When running the init script with a 'set -x' the variable $pidfile looks like this:

      + exec=zabbix_agentd
      + prog=zabbix_agentd
      + conf=/etc/zabbix/zabbix_agentd.conf
      ++ grep -e '^PidFile=.*$' /etc/zabbix/zabbix_agentd.conf
      ++ cut -d= -f2
      + pidfile=$'/var/run/zabbix/zabbix_agentd.pid\r'
      

      A workaround is to edit the init script to remove the carriage return, by changing the line:

      pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2)
      

      to

      pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2 | tr '\r' ' ')
      

      This results in:

      + exec=zabbix_agentd
      + prog=zabbix_agentd
      + conf=/etc/zabbix/zabbix_agentd.conf
      ++ grep -e '^PidFile=.*$' /etc/zabbix/zabbix_agentd.conf
      ++ cut -d= -f2
      ++ tr '\r' ' '
      + pidfile='/var/run/zabbix/zabbix_agentd.pid '
      

      and a stopped zabbix-agent. I'm not a initscript or shell guru, so if any other solution is better/nicer/less stupid, please share.

            Unassigned Unassigned
            d43m0n Dennis Ortsen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: