-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall
executable file
·91 lines (79 loc) · 3.16 KB
/
install
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
#!/bin/bash
set -o errexit
set -o xtrace
declare -A SERVICES=(
["rds"]="innodb_sb innodb_sb_spike"
["rds-dev"]="rds_test_sb"
["md"]="innodb_sb innodb_sb_spike innodb_extra aria_sb deadlock_holder deadlock_requestor defrag_sb defrag_extra onlineddl_sb onlineddl_extra"
["ps55"]="innodb_sb innodb_sb_spike innodb_extra myisam_sb myisam_extra small_sb small_extra"
["ps56"]="innodb_sb innodb_sb_spike innodb_extra myisam_sb myisam_extra small_sb small_extra"
["ps57"]="innodb_sb innodb_sb_spike innodb_extra myisam_sb myisam_extra small_sb small_extra tokudb_sb tokudb_extra"
["ps57r"]="innodb_sb_readonly innodb_extra small_sb"
["pxc56-1"]="innodb_sb innodb_sb_spike innodb_extra small_sb small_update"
["pxc56-2"]="innodb_sb_2 innodb_sb_spike_2 innodb_extra_2"
["pxc56-3"]="innodb_sb_3 innodb_sb_spike_3 innodb_extra_3 cluster_mess"
["pxc57-1"]="innodb_sb innodb_sb_spike innodb_extra small_sb small_update"
["pxc57-2"]="innodb_sb_2 innodb_sb_spike_2 innodb_extra_2"
["pxc57-3"]="innodb_sb_3 innodb_sb_spike_3 innodb_extra_3 cluster_mess"
["psrocksdb"]="innodb_sb innodb_sb_spike innodb_extra small_sb small_extra rocksdb_sb rocksdb_extra"
)
ROOT_DIR=$(realpath "$(dirname $0)")
remove_all() {
local SOCKET_NAME=$1
pushd $ROOT_DIR/loader
for LOADER in $(ls); do
if [ -e "/etc/systemd/system/loader-${LOADER}-${SOCKET_NAME}.service" ]; then
systemctl --no-reload disable "loader-${LOADER}-${SOCKET_NAME}" > /dev/null 2>&1 || :
systemctl stop "loader-${LOADER}-${SOCKET_NAME}" > /dev/null 2>&1 || :
fi
done
popd
}
create_loader() {
local LOADER=$1
local SOCKET_PATH=$2
local SOCKET_NAME=$(basename $SOCKET_PATH | sed -e 's/[.].*//')
cat - <<-EOF >/etc/systemd/system/loader-${LOADER}-${SOCKET_NAME}.service
[Unit]
Description=PMM Loader ${LOADER} for ${SOCKET_NAME} socket
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=$ROOT_DIR/loader/${LOADER} $SOCKET_PATH
Restart=always
RestartSec=120
[Install]
WantedBy=multi-user.target
EOF
systemctl preset "loader-${LOADER}-${SOCKET_NAME}"
systemctl enable "loader-${LOADER}-${SOCKET_NAME}"
systemctl start "loader-${LOADER}-${SOCKET_NAME}"
}
main() {
local TYPE=$1
local SOCKET_PATH=$2
local SOCKET_NAME=$(basename $SOCKET_PATH | sed -e 's/[.].*//')
if [[ -z "$TYPE" ]] || [[ -z "${SERVICES[$TYPE]}" ]]; then
echo "unknown server type"
echo "usage: $0 {ps|pxc|mo|ms|md} /path/to/service.socket"
exit 1
fi
if [ -S "$SOCKET_PATH" ]; then
CONNECTION="--socket=$SOCKET_PATH"
elif nslookup "$SOCKET_PATH"; then
CONNECTION="--host=$SOCKET_PATH"
else
echo "cannot find $SOCKET_PATH socket or host"
echo "usage: $0 {ps|pxc|mo|ms|md} /path/to/service.socket"
exit 1
fi
CONNECTION+=" --user ${MYSQL_USER:-root}"
[ -n "$MYSQL_PASSWORD" ] && CONNECTION+=" -p${MYSQL_PASSWORD}" || :
remove_all "$SOCKET_NAME"
mysql $CONNECTION < $ROOT_DIR/grants.sql
for LOADER in ${SERVICES[$TYPE]}; do
create_loader "$LOADER" "$SOCKET_PATH" "$SOCKET_NAME"
done
}
main "$@"
exit 0