Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
blodone authored Feb 21, 2024
2 parents 9d56525 + fa681fa commit b89336e
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions extension-files/postinstall
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
#!/bin/bash

THE_INCLUDE="Include=/usr/share/zabbix-agent-extensions/include.d/"
if [ -e /etc/zabbix/zabbix_agent2.conf ]; then
AGENT=zabbix-agent2
AGENT_INCLUDE=zabbix_agent2.d
AGENT_CONF=zabbix_agent2.conf
else
AGENT=zabbix-agent
AGENT_INCLUDE=zabbix_agentd.d
AGENT_CONF=zabbix_agentd.conf
fi

if (grep -q -P "Ubuntu|Debian|CentOS|Raspbian" /etc/os-release);then
if [ -e "/etc/zabbix/zabbix_agentd.d/zabbix-agent-extensions" ];then
echo "Notice: /etc/zabbix/zabbix_agentd.d/zabbix-agent-extensions already exists, no need to add the Include to /etc/zabbix/zabbix_agentd.conf"
elif ( [ -e /etc/zabbix/zabbix_agentd.conf ] && ! (grep -q "$THE_INCLUDE" /etc/zabbix/zabbix_agentd.conf) );then
echo "" >> /etc/zabbix/zabbix_agentd.conf
echo "#################################################################" >> /etc/zabbix/zabbix_agentd.conf
echo "# Added by postinstall of package zabbix-agent-extensions" >> /etc/zabbix/zabbix_agentd.conf
echo "$THE_INCLUDE" >> /etc/zabbix/zabbix_agentd.conf

if [ -e "/etc/zabbix/$AGENT_INCLUDE/zabbix-agent-extensions" ] || [ -e "/etc/zabbix/$AGENT_INCLUDE/zabbix-agent-extensions.conf" ];then
echo "Notice: /etc/zabbix/$AGENT_INCLUDE/zabbix-agent-extensions already exists, no need to add the Include to /etc/zabbix/$AGENT_CONF"
elif ! (grep -q "$THE_INCLUDE" /etc/zabbix/$AGENT_CONF);then
echo "" >> /etc/zabbix/$AGENT_CONF
echo "#################################################################" >> /etc/zabbix/$AGENT_CONF
echo "# Added by postinstall of package zabbix-agent-extensions" >> /etc/zabbix/$AGENT_CONF
echo "$THE_INCLUDE" >> /etc/zabbix/$AGENT_CONF_CONF

fi

if [ -e "/etc/zabbix/zabbix_agentd2.d/zabbix-agent-extensions" ];then
Expand All @@ -29,13 +40,14 @@ if (grep -q -P "Ubuntu|Debian|CentOS|Raspbian" /etc/os-release);then

mkdir -m 755 -p /etc/zabbix/zabbix-discovery-generic
chown zabbix:zabbix /etc/zabbix/zabbix-discovery-generic

if (which systemctl >/dev/null 2>&1);then
echo "Restarting with systemctl"
systemctl restart $AGENT.service
elif [ -f /etc/init.d/$AGENT ];then
echo "Restarting with /etc/init.d/$AGENT"
/etc/init.d/$AGENT restart

if ( (which systemctl >/dev/null 2>&1) && (systemctl list-unit-files zabbix-agent.service|grep -q enabled) );then
echo "Restarting zabbix-agent with systemctl"
systemctl restart zabbix-agent.service
elif [ -f /etc/init.d/zabbix-agent ];then
echo "Restarting with /etc/init.d/zabbix-agent"
/etc/init.d/zabbix-agent restart
else
echo "no known init method"
fi
Expand Down

0 comments on commit b89336e

Please sign in to comment.