/
service_rpm_priv_admin.script
94 lines (81 loc) · 2.24 KB
/
service_rpm_priv_admin.script
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
{{=<% %>=}}#!/bin/sh
#
# {{package_name}}
#
NAME={{package_service_name}}
RELEASE={{release_name}}
DAEMON_USER={{package_service_user}}
DAEMON=/usr/lib64/$RELEASE/bin/$RELEASE
# run_erl will place pipes and logs here
# NOTE: the trailing '/' is necessary for run_erl for some reason?
PIPE_DIR=/var/run/$NAME/
RUNNER_LOG_DIR=/var/log/$NAME
export PIPE_DIR RUNNER_LOG_DIR
# these overwrite default locations for configs
VMARGS_PATH=/etc/$NAME/vm.args
RELX_CONFIG_PATH=/etc/$NAME/sys.config
export VMARGS_PATH RELX_CONFIG_PATH
# Check for daemon script
[ -x $DAEMON ] || exit 0
if [ -z "$HOME" ]; then
export HOME=/var/run/$NAME
fi
# See how we were called.
case "$1" in
eval)
$DAEMON $*
;;
remsh)
$DAEMON remote_console
;;
entop)
ERL=$(ls /usr/lib64/$RELEASE/erts-*/bin/erl)
COOKIE=$($DAEMON eval 'erlang:get_cookie()')
if [ $? -ne 0 ] ; then
echo $COOKIE
exit $?
fi
# sometimes cookies have single quotes, we'll get rid of them
COOKIE=$(echo $COOKIE | cut -f2 -d"'")
NODE=$($DAEMON eval 'node()')
if [ $? -ne 0 ] ; then
echo $NODE
exit $?
fi
ID="entop$(od -t x -N 4 /dev/urandom | head -n1 | awk '{print $2}')-$NAME"
# Extract the target node name from node.args
NAME_ARG=$(egrep '^-s?name' "$VMARGS_PATH" || true)
# Perform replacement of variables in ${NAME_ARG}
NAME_ARG=$(eval echo "${NAME_ARG}")
# Extract the name type and name from the NAME_ARG for REMSH
NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')"
# when using snames you need the short host, so we need to add to our
# id in that case
case "${NAME_TYPE}" in
-sname)
# sometimes with a short name I found random extra "'' characters
ID=$ID@$(echo $NODE | cut -f2 -d'@' | cut -f1 -d"'")
;;
-name)
;;
esac
$ERL -boot start_clean \
-noinput \
-hidden \
+A 20 \
+Bc \
$NAME_TYPE $ID \
-setcookie $COOKIE \
-eval "entop:start($NODE)"
;;
passthrough)
# remove passthrough
shift
# and pass rest to daemon process
/usr/bin/sudo -u $DAEMON_USER -E -- $DAEMON $*
;;
*)
echo $"Usage: $0 {remsh|eval|entop|passthrough}"
exit 1
esac
exit $?<%={{ }}=%>