]> arthur.barton.de Git - ZabbixExtensions.git/blob - deploy.sh
Fix backup_script.errors to not report errors when a job is running
[ZabbixExtensions.git] / deploy.sh
1 #!/bin/sh
2
3 BASE_DIR=$(dirname "$0")
4 DEST_DIR="/usr/local/etc/zabbix/zabbix_agentd.conf.d"
5 ZABBIX_AGENT_OSX="/usr/local/sbin/zabbix_agentd"
6
7 # Include "ax-common.sh":
8 for dir in "$HOME/lib" "$HOME/.ax" /usr/local /opt/ax /usr; do
9         [ -z "$ax_common_sourced" ] || break
10         ax_common="${dir}/lib/ax/ax-common.sh"
11         [ -r "$ax_common" ] && . "$ax_common"
12 done
13 if [ -z "$ax_common_sourced" ]; then
14         ax_msg() {
15                 shift
16                 echo "$@"
17         }
18 fi
19 unset dir ax_common ax_common_sourced
20
21 ax_msg - "Building project ..."
22 make all check || exit 1
23 echo
24
25 restart_agent() {
26         echo "Restarting Zabbix agent ..."
27         ssh root@$1 "chmod -R a+rX '$DEST_DIR'; service zabbix-agent restart"
28         result=$?
29         if [ $result -ne 0 ]; then
30                 # Try OS X (Homebrew) variant
31                 ssh root@$1 "su - admin -c 'pkill zabbix_agentd; $ZABBIX_AGENT_OSX'"
32                 result=$?
33         fi
34         if [ $result -eq 0 ]; then
35                 ax_msg 0 "Ok, agent restarted."
36                 return 0
37         fi
38         ax_msg 2 "FAILED to restart agent (code $result)!"
39         return 1
40 }
41
42 refresh_sudo() {
43         echo "Fixing sudo configuration file permissions ..."
44         ssh root@$1 "chown 0:0 /etc/sudoers.d/zabbix-extensions; chmod 440 /etc/sudoers.d/zabbix-extensions"
45         result=$?
46         if [ $result -eq 0 ]; then
47                 ax_msg 0 "Ok, permissions fixed."
48                 return 0
49         fi
50         ax_msg 2 "FAILED to fix sudo configuration permissions (code $result)!"
51         return 1
52 }
53
54 for host in "$@"; do
55         ax_msg - "$host ..."
56
57         ssh root@$host mkdir -p /usr/local/etc/zabbix/zabbix_agentd.conf.d
58
59         # Zabbix agent configuration
60         out=$(rsync -rt --delete --log-format=%f -e ssh --exclude Makefile \
61          "$BASE_DIR/etc/zabbix_agentd.conf.d/" \
62          "root@$host:$DEST_DIR"
63         )
64         if [ $? -eq 0 ]; then
65                 changes=$(printf "%s" "$out" | wc -c)
66                 if [ $changes -gt 0 ]; then
67                         ax_msg 1 "Ok, updated Zabbix configuration."
68                         restart_agent "$host"
69                 else
70                         ax_msg 0 "Ok, no changes for Zabbix configuration."
71                 fi
72         else
73                 ax_msg 2 "Failed to sync Zabbix configuration to $host!"
74         fi
75
76         # sudo configuration
77         out=$(rsync -t --log-format=%f -e ssh \
78          "$BASE_DIR/etc/sudoers.d/zabbix-extensions" \
79          "root@$host:/etc/sudoers.d/zabbix-extensions"
80         )
81         if [ $? -eq 0 ]; then
82                 changes=$(printf "%s" "$out" | wc -c)
83                 if [ $changes -gt 0 ]; then
84                         ax_msg 1 "Ok, updated sudo configuration."
85                         refresh_sudo "$host"
86                 else
87                         ax_msg 0 "Ok, no changes for sudo configuration."
88                 fi
89         else
90                 ax_msg 2 "Failed to sync sudo configuration to $host!"
91         fi
92
93         echo
94 done