forked from deric/mesos-deb-packaging
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmesos-init-wrapper
executable file
·58 lines (48 loc) · 1.81 KB
/
mesos-init-wrapper
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
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<USAGE
USAGE: mesos-init-wrapper (master|slave)
Run Mesos in master or slave mode, loading environment files, setting up
logging and loading config parameters as appropriate.
USAGE
}; function --help { -h ;} # A nice way to handle -h and --help
export LC_ALL=en_US.UTF-8 # A locale that works consistently
function main {
err "Please use \`master' or \`slave'."
}
function slave {
local args=()
[[ ! -f /etc/default/mesos ]] || . /etc/default/mesos
[[ ! -f /etc/default/mesos-slave ]] || . /etc/default/mesos-slave
[[ ! ${ULIMIT:-} ]] || ulimit $ULIMIT
[[ ! ${MASTER:-} ]] || args+=( --master="$MASTER" )
[[ ! ${LOGS:-} ]] || args+=( --log_dir="$LOGS" )
[[ ! ${ISOLATION:-} ]] || args+=( --isolation="$ISOLATION" )
logged /usr/local/sbin/mesos-slave "${args[@]}"
}
function master {
local args=()
[[ ! -f /etc/default/mesos ]] || . /etc/default/mesos
[[ ! -f /etc/default/mesos-master ]] || . /etc/default/mesos-master
[[ ! ${ULIMIT:-} ]] || ulimit $ULIMIT
[[ ! ${ZK:-} ]] || args+=( --zk="$ZK" )
[[ ! ${PORT:-} ]] || args+=( --port="$PORT" )
[[ ! ${CLUSTER:-} ]] || args+=( --cluster="$CLUSTER" )
[[ ! ${LOGS:-} ]] || args+=( --log_dir="$LOGS" )
logged /usr/local/sbin/mesos-master "${args[@]}"
}
# Send all output to syslog and tag with PID and executable basename.
function logged {
local tag="${1##*/}[$$]"
exec 1> >(exec logger -p user.info -t "$tag")
exec 2> >(exec logger -p user.err -t "$tag")
exec "$@"
}
function msg { out "$*" >&2 ;}
function err { local x=$? ; msg "$*" ; return $(( $x == 0 ? 1 : $x )) ;}
function out { printf '%s\n' "$*" ;}
if [[ ${1:-} ]] && declare -F | cut -d' ' -f3 | fgrep -qx -- "${1:-}"
then "$@"
else main "$@"
fi