-
Notifications
You must be signed in to change notification settings - Fork 55
/
pre-start.bash
106 lines (86 loc) · 3.24 KB
/
pre-start.bash
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
#!/bin/bash -e
[ -z "$DEBUG" ] || set -x
JOB_DIR=/var/vcap/jobs/rabbitmq-server
PID_FILE=/var/vcap/sys/run/rabbitmq-server/pid
HOME_DIR=/var/vcap/store/rabbitmq
SERVICE_METRICS_DIR=/var/vcap/sys/log/service-metrics
ROOT_LOG_DIR=/var/vcap/sys/log
INIT_LOG_DIR=/var/vcap/sys/log/rabbitmq-server
HTTP_ACCESS_LOG_DIR="${INIT_LOG_DIR}"/management-ui
STARTUP_LOG="${INIT_LOG_DIR}"/startup_stdout.log
STARTUP_ERR_LOG="${INIT_LOG_DIR}"/startup_stderr.log
SHUTDOWN_LOG="${INIT_LOG_DIR}"/shutdown_stdout.log
SHUTDOWN_ERR_LOG="${INIT_LOG_DIR}"/shutdown_stderr.log
USER=vcap
source /var/vcap/packages/rabbitmq-common/ensure_dir_with_permissions
main() {
write_log "pre-start script started"
remove_old_syslog_config
ensure_dir_with_permissions "${ROOT_LOG_DIR}"
ensure_dir_with_permissions "${INIT_LOG_DIR}"
ensure_dir_with_permissions "${HTTP_ACCESS_LOG_DIR}"
ensure_dir_with_permissions "$(dirname "${PID_FILE}")"
ensure_dir_with_permissions "${HOME_DIR}"
ensure_dir_with_permissions "${JOB_DIR}"
ensure_dir_with_permissions "${SERVICE_METRICS_DIR}"
ensure_log_files
ensure_http_log_cleanup_cron_job
# shellcheck disable=SC1090
. "${JOB_DIR}"/lib/prepare-for-upgrade.bash
. "${JOB_DIR}"/lib/rabbitmq-config-vars.bash
local rmq_server_package
rmq_server_package=$(configure_rmq_version)
run_rabbitmq_upgrade_preparation_shutdown_cluster_if_cookie_changed "$ERLANG_COOKIE" "${HOME_DIR}/.erlang.cookie" "$RABBITMQ_NODES_STRING" "$rmq_server_package"
setup_erl_inetrc
add_env_to_global_shell_profile
${JOB_DIR}/bin/plugins.sh
write_log "pre-start script completed"
}
write_log() {
echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ"): $*"
}
remove_old_syslog_config() {
rm -f /etc/rsyslog.d/00-syslog_forwarder.conf
rm -f /etc/rsyslog.d/rabbitmq_syslog.conf
}
ensure_log_files() {
touch "$STARTUP_LOG"
touch "$STARTUP_ERR_LOG"
touch "$SHUTDOWN_LOG"
touch "$SHUTDOWN_ERR_LOG"
chown "$USER":"$USER" "$INIT_LOG_DIR"/startup*
chown "$USER":"$USER" "$INIT_LOG_DIR"/shutdown*
}
ensure_http_log_cleanup_cron_job() {
cp "$JOB_DIR/bin/cleanup-http-logs" /etc/cron.daily
}
configure_rmq_version() {
rm -rf /var/vcap/packages/rabbitmq-server
ln -s /var/vcap/packages/rabbitmq-server-"$RMQ_SERVER_VERSION" /var/vcap/packages/rabbitmq-server
echo "/var/vcap/packages/rabbitmq-server"
}
configure_erlang_version() {
rm -rf /var/vcap/packages/erlang
ln -s /var/vcap/packages/erlang-"$ERLANG_MAJOR_VERSION" /var/vcap/packages/erlang
echo "/var/vcap/packages/erlang"
}
setup_erl_inetrc() {
. /var/vcap/jobs/rabbitmq-server/lib/rabbitmq-config-vars.bash
configure_rmq_version
configure_erlang_version
# Unfortunate tight coupling. Beware.
# We need this for CONF_ENV_FILE, HOME, ERL_INETRC, and for MNESIA_BASE
. /var/vcap/packages/rabbitmq-server/privbin/rabbitmq-defaults
# 1. Write out our new erl_inetrc file. We do this to avoid modifying
# /etc/hosts.
# See http://erlang.org/doc/apps/erts/inet_cfg.html for more info.
DIR=$(mktemp -d)
trap "rm -rf ${DIR}" EXIT
printf "%s{lookup, [file, native]}.\n" "$ERL_INETRC_HOSTS" >> "$DIR/erl_inetrc"
cp "$DIR/erl_inetrc" "$ERL_INETRC"
mkdir -p "$(dirname "$CONF_ENV_FILE")"
}
add_env_to_global_shell_profile() {
ln -sf "$JOB_DIR/bin/env" "/etc/profile.d/rabbitmq-server-env.sh"
}
main