From 0715b8743da48eb0a300fb9910c604b29c31f1f1 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 5 Aug 2018 10:17:12 +1000 Subject: [PATCH] Add server_runas option to run server as specific user --- tools/arkmanager | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index e4c90f5f..6fcb889e 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1163,7 +1163,24 @@ doRunBG(){ [[ $fd -gt 2 && $fd != 255 ]] && exec {fd}<&- done - doRun "$@" > >(while read -r l; do printf "%s: [%s] %s\n" "$(timestamp)" "${instance}" "${l}"; done) 2>&1 + if [ -n "$server_runas" ]; then + sudo -u "$server_runas" "$0" --run-instance "$instance" <(cat "${arkstGlobalCfgFile}" "${HOME}/${arkstUserCfgFile}" 2>/dev/null; if [ -z "arkSingleInstance" && -n "$configfile" ]; then cat "$configfile" 2>/dev/null; fi) > >(while read -r l; do printf "%s: [%s] %s\n" "$(timestamp)" "${instance}" "${l}"; done) 2>&1 + else + doRun "$@" > >(while read -r l; do printf "%s: [%s] %s\n" "$(timestamp)" "${instance}" "${l}"; done) 2>&1 + fi +} + +doRunInstance(){ + instance="$1" + + if [[ -n "$2" && -r "$2" ]]; then + . "$2" + fi + + shift + shift + + doRun "$@" } # @@ -3067,11 +3084,11 @@ useConfig() { loadGlobalConfig() { if [ -f "${arkstGlobalCfgFile}" ]; then - source "${arkstGlobalCfgFile}" + source "${arkstGlobalCfgFile}" fi if [ -f "${HOME}/${arkstUserCfgFile}" ]; then - source "${HOME}/${arkstUserCfgFile}" + source "${HOME}/${arkstUserCfgFile}" fi lsof=lsof @@ -3243,6 +3260,13 @@ EOE #--------------------- main(){ + # Handle special --run-instance command + if [ "$1" == "--run-instance" ]; then + shift + doRunInstance "$@" + exit + fi + # Global variables loadGlobalConfig