fix logging for some commands and minor tidying
This commit is contained in:
@@ -75,7 +75,7 @@ function CheckUser {
|
|||||||
|
|
||||||
# Make sure the script is ran as root
|
# Make sure the script is ran as root
|
||||||
|
|
||||||
if [[ ! "$(id -u)" == "0" ]]; then
|
if [[ ! $(runcmd_stdout "id -u") == "0" ]]; then
|
||||||
printfail "This script needs to be ran as root"
|
printfail "This script needs to be ran as root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -85,13 +85,14 @@ function CheckUser {
|
|||||||
# log script version (git commit) and configuration variables to logfile
|
# log script version (git commit) and configuration variables to logfile
|
||||||
function scriptInfo {
|
function scriptInfo {
|
||||||
|
|
||||||
SCRIPTVERSION=$(runcmd_stdout "cd '$(dirname "$0")' 2>/dev/null && git rev-parse --short HEAD 2>/dev/null")
|
set -o pipefail
|
||||||
|
|
||||||
|
SCRIPTVERSION=$(cd "$(dirname "$0")" 2>/dev/null && git rev-parse --short HEAD 2>/dev/null)
|
||||||
|
|
||||||
[ -z "$SCRIPTVERSION" ] && SCRIPTVERSION="undefined"
|
[ -z "$SCRIPTVERSION" ] && SCRIPTVERSION="undefined"
|
||||||
echo "Running script version $SCRIPTVERSION with config:" >> "$LOGFILE"
|
echo "Running script version $SCRIPTVERSION with config:" >> "$LOGFILE"
|
||||||
echo >> "$LOGFILE"
|
echo >> "$LOGFILE"
|
||||||
# shellcheck disable=SC2005,SC2002
|
[ -s "$CONFIG_FILE" ] && grep -Eo '^[A-Z_]+.*' "$CONFIG_FILE" >> "$LOGFILE" || echo "No config file found" >> "$LOGFILE"
|
||||||
[ -s "$CONFIG_FILE" ] && echo "$(cat "$CONFIG_FILE" | grep -Eo '^[A-Z_]+.*')" >> "$LOGFILE" || echo "No config file found" >> "$LOGFILE"
|
|
||||||
echo >> "$LOGFILE"
|
echo >> "$LOGFILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +311,7 @@ function UpdateNodeYarn {
|
|||||||
|
|
||||||
echo
|
echo
|
||||||
printinfo "Checking current node.js version"
|
printinfo "Checking current node.js version"
|
||||||
NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1)
|
NODEV=$(runcmd_stdout "node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1")
|
||||||
|
|
||||||
if [ "$PKG_FORMAT" == "rpm" ]; then
|
if [ "$PKG_FORMAT" == "rpm" ]; then
|
||||||
if [[ -n "$NODEV" ]] && [[ "$NODEV" -lt "${NODEVERSION}" ]]; then
|
if [[ -n "$NODEV" ]] && [[ "$NODEV" -lt "${NODEVERSION}" ]]; then
|
||||||
@@ -409,9 +410,9 @@ function InstallXOPlugins {
|
|||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
runcmd "find \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/\" -maxdepth 1 -mindepth 1 -not -name \"xo-server\" -not -name \"xo-web\" -not -name \"xo-server-cloud\" -exec ln -sn {} \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/node_modules/\" \;"
|
runcmd "find \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/\" -maxdepth 1 -mindepth 1 -not -name \"xo-server\" -not -name \"xo-web\" -not -name \"xo-server-cloud\" -exec ln -sn {} \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/node_modules/\" \;"
|
||||||
else
|
else
|
||||||
local PLUGINSARRAY=($(echo "$PLUGINS" | tr ',' ' '))
|
local PLUGINSARRAY=($(runcmd_stdout "echo '$PLUGINS' | tr ',' ' '"))
|
||||||
for x in "${PLUGINSARRAY[@]}"; do
|
for x in "${PLUGINSARRAY[@]}"; do
|
||||||
if [[ $(find "$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages" -type d -name "$x") ]]; then
|
if [[ $(runcmd_stdout "find $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages -type d -name '$x'") ]]; then
|
||||||
runcmd "ln -sn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/$x $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/node_modules/"
|
runcmd "ln -sn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/$x $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/node_modules/"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -443,17 +444,15 @@ function InstallXO {
|
|||||||
# Create installation directory if doesn't exist already
|
# Create installation directory if doesn't exist already
|
||||||
if [[ ! -d "$INSTALLDIR" ]] ; then
|
if [[ ! -d "$INSTALLDIR" ]] ; then
|
||||||
echo
|
echo
|
||||||
printprog "Creating missing basedir to $INSTALLDIR"
|
printinfo "Creating missing basedir to $INSTALLDIR"
|
||||||
runcmd "mkdir -p \"$INSTALLDIR\""
|
runcmd "mkdir -p \"$INSTALLDIR\""
|
||||||
printok "Creating missing basedir to $INSTALLDIR"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create missing xo-builds directory if doesn't exist already
|
# Create missing xo-builds directory if doesn't exist already
|
||||||
if [[ ! -d "$INSTALLDIR/xo-builds" ]]; then
|
if [[ ! -d "$INSTALLDIR/xo-builds" ]]; then
|
||||||
echo
|
echo
|
||||||
printprog "Creating missing xo-builds directory to $INSTALLDIR/xo-builds"
|
printinfo "Creating missing xo-builds directory to $INSTALLDIR/xo-builds"
|
||||||
runcmd "mkdir \"$INSTALLDIR/xo-builds\""
|
runcmd "mkdir \"$INSTALLDIR/xo-builds\""
|
||||||
printok "Creating missing xo-builds directory to $INSTALLDIR/xo-builds"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
@@ -546,7 +545,7 @@ function InstallXO {
|
|||||||
if [[ $(runcmd_stdout "pgrep -f xo-server") ]]; then
|
if [[ $(runcmd_stdout "pgrep -f xo-server") ]]; then
|
||||||
echo
|
echo
|
||||||
printprog "Shutting down xo-server"
|
printprog "Shutting down xo-server"
|
||||||
/bin/systemctl stop xo-server || { printfail "failed to stop service, exiting..." ; exit 1; }
|
runcmd "/bin/systemctl stop xo-server" || { printfail "failed to stop service, exiting..." ; exit 1; }
|
||||||
printok "Shutting down xo-server"
|
printok "Shutting down xo-server"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -666,7 +665,7 @@ function InstallXO {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# fix to prevent older installations to not update because systemd service is not symlinked anymore
|
# fix to prevent older installations to not update because systemd service is not symlinked anymore
|
||||||
if [[ $(find /etc/systemd/system -maxdepth 1 -type l -name "xo-server.service") ]]; then
|
if [[ $(runcmd_stdout "find /etc/systemd/system -maxdepth 1 -type l -name 'xo-server.service'") ]]; then
|
||||||
runcmd "rm -f /etc/systemd/system/xo-server.service"
|
runcmd "rm -f /etc/systemd/system/xo-server.service"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -693,12 +692,12 @@ function InstallXO {
|
|||||||
count=0
|
count=0
|
||||||
limit=6
|
limit=6
|
||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
servicestatus="$(journalctl --since "$LOGTIME" -u xo-server | grep "Web server listening on https\{0,1\}:\/\/.*:$PORT")"
|
servicestatus="$(runcmd_stdout "journalctl --since '$LOGTIME' -u xo-server | grep 'Web server listening on https\{0,1\}:\/\/.*:$PORT'")"
|
||||||
while [[ -z "$servicestatus" ]] && [[ "$count" -lt "$limit" ]]; do
|
while [[ -z "$servicestatus" ]] && [[ "$count" -lt "$limit" ]]; do
|
||||||
echo " waiting for port to be open"
|
echo " waiting for port to be open"
|
||||||
sleep 10
|
sleep 10
|
||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
servicestatus="$(journalctl --since "$LOGTIME" -u xo-server | grep "Web server listening on https\{0,1\}:\/\/.*:$PORT")"
|
servicestatus="$(runcmd_stdout "journalctl --since '$LOGTIME' -u xo-server | grep 'Web server listening on https\{0,1\}:\/\/.*:$PORT'")"
|
||||||
(( count++ ))
|
(( count++ ))
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -725,7 +724,7 @@ function InstallXO {
|
|||||||
echo "$TASK failed" >> "$LOGFILE"
|
echo "$TASK failed" >> "$LOGFILE"
|
||||||
echo "xo-server service log:" >> "$LOGFILE"
|
echo "xo-server service log:" >> "$LOGFILE"
|
||||||
echo "" >> "$LOGFILE"
|
echo "" >> "$LOGFILE"
|
||||||
journalctl --since "$LOGTIME" -u xo-server >> "$LOGFILE"
|
runcmd "journalctl --since '$LOGTIME' -u xo-server >> $LOGFILE"
|
||||||
echo
|
echo
|
||||||
echo "Control xo-server service with systemctl for stop/start/restart etc."
|
echo "Control xo-server service with systemctl for stop/start/restart etc."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -1075,7 +1074,7 @@ read -r -p ": " option
|
|||||||
|
|
||||||
case $option in
|
case $option in
|
||||||
1)
|
1)
|
||||||
if [[ $(pgrep -f xo-server) ]]; then
|
if [[ $(runcmd_stdout "pgrep -f xo-server") ]]; then
|
||||||
echo "Looks like xo-server process is already running, consider running update instead. Continue anyway?"
|
echo "Looks like xo-server process is already running, consider running update instead. Continue anyway?"
|
||||||
read -r -p "[y/N]: " answer
|
read -r -p "[y/N]: " answer
|
||||||
case $answer in
|
case $answer in
|
||||||
|
Reference in New Issue
Block a user