This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor consul_agent job to use pre-start script
- monit now runs the agent_ctl script as vcap - all privileged commands run in the pre-start script [#119388013]
- Loading branch information
Showing
4 changed files
with
77 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash -exu | ||
|
||
LOG_DIR=/var/vcap/sys/log/consul_agent | ||
RUN_DIR=/var/vcap/sys/run/consul_agent | ||
DATA_DIR=/var/vcap/store/consul_agent | ||
CONF_DIR=/var/vcap/jobs/consul_agent/config | ||
CERT_DIR=$CONF_DIR/certs | ||
PKG=/var/vcap/packages/consul | ||
|
||
function setup_resolvconf() { | ||
local resolvconf_file | ||
resolvconf_file=/etc/resolvconf/resolv.conf.d/head | ||
|
||
if ! grep -qE '127.0.0.1\b' "${resolvconf_file}"; then | ||
if [[ "$(stat -c "%s" "${resolvconf_file}")" = "0" ]]; then | ||
echo 'nameserver 127.0.0.1' > "${resolvconf_file}" | ||
else | ||
sed -i -e '1i nameserver 127.0.0.1' "${resolvconf_file}" | ||
fi | ||
fi | ||
|
||
resolvconf -u | ||
} | ||
|
||
function create_directories_and_chown_to_vcap() { | ||
mkdir -p "${LOG_DIR}" | ||
chown -R vcap:vcap "${LOG_DIR}" | ||
|
||
mkdir -p "${RUN_DIR}" | ||
chown -R vcap:vcap "${RUN_DIR}" | ||
|
||
mkdir -p "${DATA_DIR}" | ||
chown -R vcap:vcap "${DATA_DIR}" | ||
|
||
mkdir -p "${CONF_DIR}" | ||
chown -R vcap:vcap "${CONF_DIR}" | ||
|
||
chown vcap:vcap ${CERT_DIR}/*.{crt,key} | ||
chmod 640 ${CERT_DIR}/*.{crt,key} | ||
} | ||
|
||
function set_virtual_memory() { | ||
# "Consul uses a significant amount of virtual memory, since LMDB uses | ||
# mmap() underneath. It uses about 700MB of a 32bit system and 40GB on a | ||
# 64bit system." | ||
# | ||
# this mainly applies to bosh-lite | ||
ulimit -v unlimited | ||
ulimit -n 4096 | ||
} | ||
|
||
function setup() { | ||
create_directories_and_chown_to_vcap | ||
|
||
set_virtual_memory | ||
|
||
setup_resolvconf | ||
|
||
setcap cap_net_bind_service=+ep ${PKG}/bin/consul | ||
} | ||
|
||
setup |