Skip to content

Commit 9b63a91

Browse files
committed
Added DE and DEM init/setup scripts
1 parent 266169a commit 9b63a91

File tree

5 files changed

+115
-6
lines changed

5 files changed

+115
-6
lines changed

package/rpm/decisionengine-init.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: 2017 Fermi Research Alliance, LLC
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Initialization script for Decision Engine and its modules
7+
# It will run all the executable files in DE_INIT_DIR
8+
# Assuming that all scripts do only persistent changes on the file system and are idempotent
9+
DE_INIT_DIR=/etc/decisionengine/init.d
10+
DE_INIT_LAST="$DE_INIT_DIR"/.lastrun
11+
12+
# Emulate function library.
13+
success() {
14+
echo -en "\033[60G[OK]"
15+
return 0
16+
}
17+
18+
failure() {
19+
echo -en "\033[60G[FAILED]"
20+
return 1
21+
}
22+
23+
log_debug() {
24+
[[ -z "$DECISIONENGINE_DEBUG" ]] || echo "$@"
25+
}
26+
27+
if [[ -d "$DE_INIT_DIR" ]]; then
28+
# Check if the init scripts changed from the last execution
29+
# if [ -f $TSTF ] && find ./start -newer $TSTF -print -exec false {} + -quit; then echo "NO new"; else echo GO; touch $TSTF; fi
30+
if [[ -f "$DE_INIT_LAST" ]] && find "$DE_INIT_DIR" -newer "$DE_INIT_LAST" -exec false {} + -quit; then
31+
log_debug "No new Decision Engine init file"
32+
exit 0
33+
fi
34+
touch "$DE_INIT_LAST"
35+
36+
# Running the scripts
37+
pushd "$DE_INIT_DIR" || exit 1
38+
for i in *; do
39+
[[ -x "$i" ]] || continue
40+
log_debug -n "Running '$i':"
41+
if ./"$i"; then
42+
log_debug OK
43+
else
44+
log_debug FAILED
45+
fi
46+
done
47+
popd || exit 1
48+
fi

package/rpm/decisionengine-wrapper.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ DE_USER=decisionengine
1212
DE_CMD=$(basename "$0")
1313
DE_HOME=$(getent passwd "$DE_USER" | cut -d: -f6 )
1414

15+
# DECISIONENGINE_DEBUG - debug enabled if not empty (debug flags possible in the future)
16+
if echo "$*" | grep "--debug"; then
17+
DECISIONENGINE_DEBUG=true
18+
export DECISIONENGINE_DEBUG
19+
fi
20+
1521
# Check if decisionengine Python code is installed
1622
# Library ~$DE_USER/.local/lib/python3.9/site-packages/decisionengine
1723
DE_EXPECTED="$DE_HOME/.local/bin/decisionengine"
@@ -20,10 +26,11 @@ if [ ! -f "$DE_EXPECTED" ]; then
2026
echo "WARNING. decisionengine command not found in $DE_EXPECTED."
2127
echo "The command will likely fail. Was the Python code installed? Use decisionengine-install-python"
2228
fi
23-
# Run the command, with su if needed
24-
if [ "$UID" -eq 0 ]; then
29+
# Run the command, with su if needed. NOTE that decisionengine-init can run only as root
30+
if [ "$(id -u)" -eq 0 ]; then
31+
decisionengine-init.sh
2532
# su -s /bin/bash -l $DE_USER -c "export PATH=\"\$HOME/.local/bin:\$PATH\"; echo \$PATH; command -v \"$DE_CMD\"; \"$DE_CMD\" $(for i in "$@"; do echo -n "\"$i\" "; done;); echo \"Test END\""
26-
su -s /bin/bash -l -c "export PATH=\"\$HOME/.local/bin:\$PATH\"; \"$DE_CMD\" $(for i in "$@"; do echo -n "\"$i\" "; done;)" $DE_USER
33+
su -s /bin/bash -l -c "export PATH=\"\$HOME/.local/bin:\$PATH\"; \"$DE_CMD\" $(for i in "$@"; do printf "%s" "\"$i\" "; done;)" $DE_USER
2734
elif [ "$(whoami)" = "$DE_USER" ]; then
2835
export PATH="$HOME/.local/bin:$PATH"
2936
"$DE_CMD" "$@"

package/rpm/decisionengine.spec

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,13 @@ install -d $RPM_BUILD_ROOT%{decisionengine_home}/passwords.d
164164
install -d $RPM_BUILD_ROOT%{decisionengine_home}/tokens.d
165165
install -d $RPM_BUILD_ROOT%{_sysconfdir}/decisionengine
166166
install -d $RPM_BUILD_ROOT%{_sysconfdir}/decisionengine/config.d
167+
install -d $RPM_BUILD_ROOT%{_sysconfdir}/decisionengine/init.d
167168
install -d $RPM_BUILD_ROOT%{_localstatedir}/log/decisionengine
168169
install -m 0644 %{src_de_base}/config/decision_engine.jsonnet $RPM_BUILD_ROOT%{_sysconfdir}/decisionengine/
169170
install -D -m 0644 %{src_de_package}/systemd/decisionengine.service $RPM_BUILD_ROOT%{_unitdir}/decisionengine.service
170171
install -D -m 0644 %{src_de_package}/systemd/decisionengine_sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/decisionengine
172+
install -D -m 0755 %{src_de_package}/rpm/decisionengine-init.sh $RPM_BUILD_ROOT%{_bindir}/decisionengine-init.sh
173+
install -D -m 0755 %{src_de_package}/rpm/dem_glideinwms.sh $RPM_BUILD_ROOT%{_sysconfdir}/init.d/dem_glideinwms.sh
171174
install -D -m 0755 %{src_de_package}/rpm/decisionengine-wrapper.sh $RPM_BUILD_ROOT%{_bindir}/decisionengine-wrapper.sh
172175
install -D -m 0755 %{src_de_package}/rpm/decisionengine-install-python.sh $RPM_BUILD_ROOT%{_bindir}/decisionengine-install-python
173176
# Add links to the wrapper script for all decisionengine binaries
@@ -224,6 +227,7 @@ systemctl daemon-reload || true
224227
%dir %attr(700, decisionengine, decisionengine) %{decisionengine_home}/tokens.d
225228
%dir %{_sysconfdir}/decisionengine
226229
%dir %{_sysconfdir}/decisionengine/config.d
230+
%dir %{_sysconfdir}/decisionengine/init.d
227231
%config(noreplace) %{_sysconfdir}/decisionengine/decision_engine.jsonnet
228232
%attr(-, root, root) %{_unitdir}/decisionengine.service
229233
%attr(-, root, root) %config(noreplace) %{_sysconfdir}/sysconfig/decisionengine
@@ -239,6 +243,7 @@ systemctl daemon-reload || true
239243
%attr(-, decisionengine, decisionengine) %dir %{_localstatedir}/log/decisionengine
240244

241245
%files modules-deps
246+
%config(noreplace) %{_sysconfdir}/decisionengine/init.d/dem_glideinwms.sh
242247

243248
%files standalone
244249

package/rpm/dem_glideinwms.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: 2017 Fermi Research Alliance, LLC
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Initialization script for the GlideinWMS module in Decision Engine Modules
7+
# This should run before running Decision Engine with the GlideinWMS module
8+
9+
DE_USER=decisionengine
10+
DE_PASS_NAME=${DE_USER^^}
11+
DE_HOME=$(getent passwd "$DE_USER" | cut -d: -f6 )
12+
13+
check_idtoken_password() {
14+
# Make sure that the IDTOKEN password exists
15+
local de_password="$DE_HOME"/passwords.d/$DE_PASS_NAME
16+
if [ ! -f "$de_password" ]; then
17+
local htc_password=/etc/condor/passwords.d/$DE_PASS_NAME
18+
if [ ! -f "$htc_password" ]; then
19+
openssl rand -base64 64 | /usr/sbin/condor_store_cred -u "$DE_USER@$(hostname -f)" -f "$htc_password" add > /dev/null 2>&1
20+
fi
21+
if [ ! -f "$htc_password" ]; then
22+
echo 'Cannot create IDTOKENs password! Check if HTCondor is installed correctly'
23+
exit 1
24+
fi
25+
/bin/cp "$htc_password" "$de_password"
26+
chown $DE_USER: "$de_password"
27+
# The permission of $DE_HOME/passwords.d/${pass_fname} should be 0600
28+
if [ ! -f "$de_password" ]; then
29+
echo 'Cannot create IDTOKENs password! Check if HTCondor is installed correctly'
30+
exit 1
31+
fi
32+
fi
33+
}
34+
35+
check_idtoken_password
36+
37+
# TODO: this is changing another RPM's files. A better solution is desired
38+
# Make sure the decisionengine user ($DE_USER) is in the glidein group
39+
if [[ -d /etc/gwms-frontend ]]; then
40+
chown -R $DE_USER: /etc/gwms-frontend
41+
else
42+
echo '/etc/gwms-frontend is missing! Was the GlideinWMS Frontend installed?'
43+
exit 1
44+
fi

package/systemd/decisionengine.service

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ After = network.target
1010
[Service]
1111
Type = simple
1212
EnvironmentFile = -/etc/sysconfig/decisionengine
13-
User = decisionengine
14-
Group = decisionengine
1513
PrivateTmp = true
14+
15+
# + in ExecStartPre/ExecStart should allow o run as root (process is executed with full privileges)
16+
# But it seems not to work, at least in the systemctl emulation, so running as root and switching in the script wrapper
17+
# User = decisionengine
18+
# Group = decisionengine
19+
# ExecStartPre = +/usr/bin/decisionengine-init.sh
1620
ExecStart = /usr/bin/decisionengine "$DE_OPTS"
17-
ExecStop = /usr/bin/echo "Running /usr/bin/de-client --stop" >&2
21+
# The specified command should be a synchronous operation, not an asynchronous one
22+
# Only one command allowed: ExecStop = /usr/bin/echo "Running /usr/bin/de-client --stop" >&2
1823
ExecStop = /usr/bin/de-client --stop
1924
# ExecReload=/usr/sbin/decsionengine reload $MAINPID
2025

0 commit comments

Comments
 (0)