Skip to content

Commit

Permalink
[WFCORE-6935] Review launch.sh, add the ability to confirm the change…
Browse files Browse the repository at this point in the history
…s and allow specify areguments in any order
  • Loading branch information
yersan committed Oct 21, 2024
1 parent 6d567a1 commit d13f263
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,88 @@
# assuming that the server home will be the one that hold this script file.
# It also allows to specify the user and group that will run the server.

function print_usage() {
echo "INFO: Usage: "
echo "${SCRIPT_NAME} -m,--mode standalone|domain [-u,--user user] [-g,--group group] [-c,--confirm y|n]"

exit 1
}

SCRIPT_NAME=$(basename "$0")
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
JBOSS_HOME="$(realpath "${SCRIPT_DIR}/../..")"
JBOSS_SYSTEMD_MODE="${1}"

if [ -z "${JBOSS_SYSTEMD_MODE}" ]; then
echo "INFO: Usage: "
echo "${SCRIPT_NAME} standalone|domain [user name] [group name]"
exit 0;
JBOSS_SYSTEMD_MODE=""
JBOSS_SYSTEMD_USER="wildfly"
JBOSS_SYSTEMD_GROUP="wildfly"
JBOSS_CONFIRM="n"

while [ "$#" -gt 0 ]
do
# For each argument option, checks whether the argument length is zero or starts with hyphen(s)
case "$1" in
-m|--mode)
if [ -z "$2" ] || [ ! "$2" = `echo "$2" | sed 's/^-*//'` ]; then
echo "Error: Missing argument for $1" >&2
print_usage
fi
JBOSS_SYSTEMD_MODE="$2"
shift 2
;;
-u|--user)
if [ -z "$2" ] || [ ! "$2" = `echo "$2" | sed 's/^-*//'` ]; then
echo "Error: Missing argument for $1" >&2
print_usage
fi
JBOSS_SYSTEMD_USER="$2"
shift 2
;;
-g|--group)
if [ -z "$2" ] || [ ! "$2" = `echo "$2" | sed 's/^-*//'` ]; then
echo "Error: Missing argument for $1" >&2
print_usage
fi
JBOSS_SYSTEMD_GROUP="$2"
shift 2
;;
-c|--confirm)
if [ -z "$2" ] || [ ! "$2" = `echo "$2" | sed 's/^-*//'` ]; then
echo "Error: Missing argument for $1" >&2
print_usage
fi
JBOSS_CONFIRM="$2"
shift 2
;;
*)
echo "Error: Unknown argument $1" >&2
print_usage
;;
esac
done

if [ "${JBOSS_SYSTEMD_MODE}" != "standalone" ] && [ "${JBOSS_SYSTEMD_MODE}" != "domain" ]; then
print_usage
fi

SYSTEMD_FILE="${SCRIPT_DIR}/wildfly-${JBOSS_SYSTEMD_MODE}.service"
JBOSS_SYSTEMD_USER="${2:-wildfly}"
JBOSS_SYSTEMD_GROUP="${3:-wildfly}"

echo "INFO: systemd unit file to generate: ${SYSTEMD_FILE}"
echo "INFO: Using JBOSS_HOME: ${JBOSS_HOME}"
echo "INFO: User: ${JBOSS_SYSTEMD_USER}"
echo "INFO: Group: ${JBOSS_SYSTEMD_GROUP}"
echo "INFO: Confirm: ${JBOSS_CONFIRM}"

while true; do
read -p "Do you want to generate ${SYSTEMD_FILE}? (y/n): " choice
case "$choice" in
y|Y ) break;;
n|N ) echo "Operation cancelled."; exit 1;;
* ) ;;
esac
done
if [ 'y' != "${JBOSS_CONFIRM}" ] && [ 'Y' != "${JBOSS_CONFIRM}" ];then
while true; do
read -p "Do you want to generate ${SYSTEMD_FILE}? (y/n): " choice
case "$choice" in
y|Y ) break;;
n|N ) echo "Operation cancelled."; exit 1;;
* ) ;;
esac
done
fi

sed -e "s|@@@JBOSS_SYSTEMD_SERVER_HOME@@@|${JBOSS_HOME}|g" \
-e "s|@@@JBOSS_SYSTEMD_USER@@@|${JBOSS_SYSTEMD_USER}|g" \
Expand All @@ -47,7 +101,7 @@ echo "INFO: Use ${JBOSS_HOME}/bin/systemd/wildfly-${JBOSS_SYSTEMD_MODE}.conf to
echo "INFO: After configuring your environment, to install the server as a systemd service do the following:"
echo ""
echo "sudo cp ${SYSTEMD_FILE} $(pkg-config systemd --variable=systemdsystemunitdir)"
echo "sudo cp ${JBOSS_HOME}/bin/systemd/wildfly-${JBOSS_SYSTEMD_MODE}.conf /etc/sysconfig/wildfly-${JBOSS_SYSTEMD_MODE}.conf"
echo "sudo cp ${JBOSS_HOME}/bin/systemd/wildfly-${JBOSS_SYSTEMD_MODE}.conf /etc/sysconfig"
echo "sudo systemctl daemon-reload"
echo "sudo systemctl start $(basename "${SYSTEMD_FILE}")"
echo ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ fi
echo "INFO: Systemd Unit File server launch script"

# Disable color output for the standard output
export JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.logmanager.nocolor=true"
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_OPTS="${JAVA_OPTS} -Dorg.jboss.logmanager.nocolor=true"
export PATH="${JAVA_HOME}/bin:${PATH}"

logDir=$(dirname $WILDFLY_CONSOLE_LOG)
if [ ! -d "$logDir" ]; then
mkdir -p "$logDir"
logDir=$(dirname "${WILDFLY_CONSOLE_LOG}")
if [ ! -d "${logDir}" ]; then
mkdir -p "${logDir}"
fi

wildflyOpts="$WILDFLY_OPTS"
if [ -n "$WILDFLY_SUSPEND_TIMEOUT" ]; then
wildflyOpts="-Dorg.wildfly.sigterm.suspend.timeout=$WILDFLY_SUSPEND_TIMEOUT $wildflyOpts"
wildflyOpts="${WILDFLY_OPTS}"
if [ -n "${WILDFLY_SUSPEND_TIMEOUT}" ]; then
wildflyOpts="-Dorg.wildfly.sigterm.suspend.timeout=${WILDFLY_SUSPEND_TIMEOUT} ${wildflyOpts}"
fi

if [ -z "$WILDFLY_HOST_CONFIG" ]; then
${WILDFLY_SH} -c "$WILDFLY_SERVER_CONFIG" -b $WILDFLY_BIND $wildflyOpts > "$WILDFLY_CONSOLE_LOG" 2>&1
if [ -z "${WILDFLY_HOST_CONFIG}" ]; then
"${WILDFLY_SH}" -c "${WILDFLY_SERVER_CONFIG}" -b "${WILDFLY_BIND}" ${wildflyOpts} > "${WILDFLY_CONSOLE_LOG}" 2>&1
else
${WILDFLY_SH} --host-config="$WILDFLY_HOST_CONFIG" -c "$WILDFLY_SERVER_CONFIG" -b $WILDFLY_BIND $wildflyOpts > "$WILDFLY_CONSOLE_LOG" 2>&1
"${WILDFLY_SH}" --host-config="${WILDFLY_HOST_CONFIG}" -c "${WILDFLY_SERVER_CONFIG}" -b "${WILDFLY_BIND}" ${wildflyOpts} > "${WILDFLY_CONSOLE_LOG}" 2>&1
fi

0 comments on commit d13f263

Please sign in to comment.