-
Notifications
You must be signed in to change notification settings - Fork 21
/
postinst.sh
131 lines (103 loc) · 2.94 KB
/
postinst.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
LOG_DIR=/var/log/amonagent
SCRIPT_DIR=/opt/amonagent/scripts/
HOME_DIR=/home/amonagent
function install_init {
cp -f $SCRIPT_DIR/init.sh /etc/init.d/amonagent
chmod +x /etc/init.d/amonagent
echo "### You can start amonagent by executing"
echo ""
echo " sudo service amonagent start"
echo ""
echo "###"
}
function install_systemd {
cp -f $SCRIPT_DIR/amonagent.service /lib/systemd/system/amonagent.service
systemctl enable amonagent || true
systemctl daemon-reload || true
echo "### You can start amonagent by executing"
echo ""
echo "sudo systemctl amonagent start"
echo ""
echo "###"
}
function install_update_rcd {
update-rc.d amonagent defaults
}
function install_chkconfig {
chkconfig --add amonagent
}
id amonagent &>/dev/null
if [[ $? -ne 0 ]]; then
useradd --system --user-group --key USERGROUPS_ENAB=yes -M amonagent --shell /bin/false -d /etc/opt/amonagent
fi
test -d $LOG_DIR || mkdir -p $LOG_DIR
chown -R -L amonagent:amonagent $LOG_DIR
chmod 755 $LOG_DIR
# Create a dummy home directory, Sensu plugins need this for some reason
test -d $HOME_DIR || mkdir -p $HOME_DIR
chown -R -L amonagent:amonagent $HOME_DIR
# Remove legacy symlink, if it exists
if [[ -L /etc/init.d/amonagent ]]; then
rm -f /etc/init.d/amonagent
fi
# Add defaults file, if it doesn't exist
if [[ ! -f /etc/default/amonagent ]]; then
touch /etc/default/amonagent
fi
# Make sure the config directory exists
if [ ! -d /etc/opt/amonagent ]; then
mkdir -p /etc/opt/amonagent
fi
# Make sure the plugin config directory exists
if [ ! -d /etc/opt/amonagent/plugins-enabled ]; then
mkdir -p /etc/opt/amonagent/plugins-enabled
fi
# Make sure the pid directory exists
if [ ! -d /var/run/amonagent ]; then
mkdir -p /var/run/amonagent
fi
chown -R -L amonagent:amonagent /var/run/amonagent
chmod 775 /var/run/amonagent
# Make sure the binary is executable
chmod +x /usr/bin/amonagent
chmod +x /opt/amonagent/amonagent
# Distribution-specific logic
if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
install_systemd
else
# Assuming sysv
install_init
install_chkconfig
fi
elif [[ -f /etc/debian_version ]]; then
# Debian/Ubuntu logic
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
install_systemd
systemctl restart amonagent || echo "WARNING: systemd not running."
else
# Assuming sysv
install_init
install_update_rcd
invoke-rc.d amonagent restart
fi
elif [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ $ID = "amzn" ]]; then
# Amazon Linux logic
install_init
install_chkconfig
fi
fi
# Generate machine id, if it does not exists
if [ ! -d /etc/opt/amonagent/machine-id ]; then
echo "### Checking machine id:"
echo ""
amonagent -machineid
echo ""
echo "###"
fi