[jboss-jira] [JBoss JIRA] (WFLY-4570) wildfly-init-debian.sh fails on Ubuntu 15.04

Luis Henrique Guiraldelli (JIRA) issues at jboss.org
Wed Oct 14 15:30:00 EDT 2015


    [ https://issues.jboss.org/browse/WFLY-4570?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13118409#comment-13118409 ] 

Luis Henrique Guiraldelli commented on WFLY-4570:
-------------------------------------------------

Basically, we replace all occurrences of 'log_******' by 'echo'. And finally, line 152, replace 'pidofproc' by 'pidof'.
I hope it helps you, guys.
Below I printed my version of the script.

#!/bin/sh
#
# /etc/init.d/wildfly -- startup script for WildFly
#
# Written by Jorge Solorzano
#
### BEGIN INIT INFO
# Provides:             wildfly
# Required-Start:       $remote_fs $network
# Required-Stop:        $remote_fs $network
# Should-Start:         $named
# Should-Stop:          $named
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    WildFly Application Server
# Description:          Provide WildFly startup/shutdown script
### END INIT INFO

NAME=wildfly
DESC="WildFly Application Server"
DEFAULT="/etc/default/$NAME"

# Check privileges
if [ `id -u` -ne 0 ]; then
        echo "You need root privileges to run this script"
        exit 1
fi

# Make sure wildfly is started with system locale
if [ -r /etc/default/locale ]; then
        . /etc/default/locale
        export LANG
fi

#. /lib/lsb/init-functions

if [ -r /etc/default/rcS ]; then
        . /etc/default/rcS
fi

# Overwrite settings from default file
if [ -f "$DEFAULT" ]; then
        . "$DEFAULT"
fi

# Location of JDK
if [ -n "$JAVA_HOME" ]; then
        export JAVA_HOME
fi

# Setup the JVM
if [ -z "$JAVA" ]; then
        if [ -n "$JAVA_HOME" ]; then
                JAVA="$JAVA_HOME/bin/java"
        else
                JAVA="java"
        fi
fi

# Location of wildfly
if [ -z "$JBOSS_HOME" ]; then
        JBOSS_HOME="/opt/wildfly"
fi
export JBOSS_HOME

# Check if wildfly is installed
if [ ! -f "$JBOSS_HOME/jboss-modules.jar" ]; then
        echo "$NAME is not installed in \"$JBOSS_HOME\""
        exit 1
fi

# Run as wildfly user
# Example of user creation for Debian based:
# adduser --system --group --no-create-home --home $JBOSS_HOME --disabled-login wildfly
if [ -z "$JBOSS_USER" ]; then
        JBOSS_USER=wildfly
fi

# Check wildfly user
id $JBOSS_USER > /dev/null 2>&1
if [ $? -ne 0 -o -z "$JBOSS_USER" ]; then
        echo "User \"$JBOSS_USER\" does not exist..."
        exit 1
fi

# Check owner of JBOSS_HOME
if [ ! $(stat -L -c "%U" "$JBOSS_HOME") = $JBOSS_USER ]; then
        echo "The user \"$JBOSS_USER\" is not owner of \"$JBOSS_HOME\""
        exit 1
fi

# Startup mode of wildfly
if [ -z "$JBOSS_MODE" ]; then
        JBOSS_MODE=standalone
fi

# Startup mode script
if [ "$JBOSS_MODE" = "standalone" ]; then
        JBOSS_SCRIPT="$JBOSS_HOME/bin/standalone.sh"
        if [ -z "$JBOSS_CONFIG" ]; then
                JBOSS_CONFIG=standalone.xml
        fi
else
        JBOSS_SCRIPT="$JBOSS_HOME/bin/domain.sh"
        if [ -z "$JBOSS_DOMAIN_CONFIG" ]; then
                JBOSS_DOMAIN_CONFIG=domain.xml
        fi
        if [ -z "$JBOSS_HOST_CONFIG" ]; then
                JBOSS_HOST_CONFIG=host.xml
        fi
fi

# Check startup file
if [ ! -x "$JBOSS_SCRIPT" ]; then
        echo "$JBOSS_SCRIPT is not an executable!"
        exit 1
fi

# Check cli file
JBOSS_CLI="$JBOSS_HOME/bin/jboss-cli.sh"
if [ ! -x "$JBOSS_CLI" ]; then
        echo "$JBOSS_CLI is not an executable!"
        exit 1
fi

# The amount of time to wait for startup
if [ -z "$STARTUP_WAIT" ]; then
        STARTUP_WAIT=30
fi

# The amount of time to wait for shutdown
if [ -z "$SHUTDOWN_WAIT" ]; then
        SHUTDOWN_WAIT=30
fi

# Location to keep the console log
if [ -z "$JBOSS_CONSOLE_LOG" ]; then
        JBOSS_CONSOLE_LOG="/var/log/$NAME/console.log"
fi
export JBOSS_CONSOLE_LOG

# Location to set the pid file
JBOSS_PIDFILE="/var/run/$NAME/$NAME.pid"
export JBOSS_PIDFILE

# Launch wildfly in background
LAUNCH_JBOSS_IN_BACKGROUND=1
export LAUNCH_JBOSS_IN_BACKGROUND

# Helper function to check status of wildfly service
check_status() {
        pidof "$JBOSS_PIDFILE" "$JAVA" >/dev/null 2>&1
}

case "$1" in
 start)
        echo "Starting $DESC" "$NAME"
        check_status
        status_start=$?
        if [ $status_start -eq 1 ]; then
                mkdir -p $(dirname "$JBOSS_PIDFILE")
                mkdir -p $(dirname "$JBOSS_CONSOLE_LOG")
                chown $JBOSS_USER $(dirname "$JBOSS_PIDFILE") || true
                cat /dev/null > "$JBOSS_CONSOLE_LOG"

                if [ "$JBOSS_MODE" = "standalone" ]; then
                        start-stop-daemon --start --user "$JBOSS_USER" \
                        --chuid "$JBOSS_USER" --chdir "$JBOSS_HOME" --pidfile "$JBOSS_PIDFILE" \
                        --exec "$JBOSS_SCRIPT" -- -c $JBOSS_CONFIG $JBOSS_OPTS >> "$JBOSS_CONSOLE_LOG" 2>&1 &
                else
                        start-stop-daemon --start --user "$JBOSS_USER" \
                        --chuid "$JBOSS_USER" --chdir "$JBOSS_HOME" --pidfile "$JBOSS_PIDFILE" \
                        --exec "$JBOSS_SCRIPT" -- --domain-config=$JBOSS_DOMAIN_CONFIG \
                        --host-config=$JBOSS_HOST_CONFIG $JBOSS_OPTS >> "$JBOSS_CONSOLE_LOG" 2>&1 &
                fi

                count=0
                launched=0
                until [ $count -gt $STARTUP_WAIT ]
                do
                        grep 'WFLYSRV0025:' "$JBOSS_CONSOLE_LOG" > /dev/null
                        if [ $? -eq 0 ] ; then
                                launched=1
                                break
                        fi
                        sleep 1
                        count=$((count + 1));
                done

                if check_status; then
                        exit 0
                else
                        exit 1
                fi

                if [ $launched -eq 0 ]; then
                        echo "$DESC hasn't started within the timeout allowed"
                        echo "please review file \"$JBOSS_CONSOLE_LOG\" to see the status of the service"
                fi
        elif [ $status_start -eq 0 ]; then
                echo "$DESC (already running)"
        fi
 ;;
 stop)
        check_status
        status_stop=$?
        if [ $status_stop -eq 0 ]; then
                read kpid < "$JBOSS_PIDFILE"
                echo "Stopping $DESC" "$NAME"

                children_pids=$(pgrep -P $kpid)

                start-stop-daemon --stop --quiet --pidfile "$JBOSS_PIDFILE" \
                --user "$JBOSS_USER" --retry=TERM/$SHUTDOWN_WAIT/KILL/5 \
                >/dev/null 2>&1

                if [ $? -eq 2 ]; then
                        echo "$DESC can't be stopped"
                        exit 1
                fi

                for child in $children_pids; do
                        /bin/kill -9 $child >/dev/null 2>&1
                done

                exit 0
        elif [ $status_stop -eq 1 ]; then
                echo "$DESC is not running but the pid file exists, cleaning up"
                rm -f $JBOSS_PIDFILE
        elif [ $status_stop -eq 3 ]; then
                echo "$DESC is not running"
        fi
 ;;
 restart)
        check_status
        status_restart=$?
        if [ $status_restart -eq 0 ]; then
                $0 stop
        fi
        $0 start
 ;;
 reload|force-reload)
        check_status
        status_reload=$?
        if [ $status_reload -eq 0 ]; then
                echo "Reloading $DESC config" "$NAME"

                if [ "$JBOSS_MODE" = "standalone" ]; then
                        RELOAD_CMD=":reload"; else
                        RELOAD_CMD=":reload-servers"; fi

                start-stop-daemon --start --chuid "$JBOSS_USER" \
                --exec "$JBOSS_CLI" -- --connect --command=$RELOAD_CMD >/dev/null 2>&1

                if [ $? -eq 0 ]; then
                        exit 0
                else
                        exit 1
                fi
        else
                echo "$DESC is not running"
        fi
 ;;
 status)
        check_status
        status=$?
        if [ $status -eq 0 ]; then
                read pid < $JBOSS_PIDFILE
                echo "$DESC is running with pid $pid"
                exit 0
        elif [ $status -eq 1 ]; then
                echo "$DESC is not running and the pid file exists"
                exit 1
        elif [ $status -eq 3 ]; then
                echo "$DESC is not running"
                exit 3
        else
                echo "Unable to determine $NAME status"
                exit 4
        fi
 ;;
 *)
 echo "Usage: $0 {start|stop|restart|reload|force-reload|status}"
 exit 2
 ;;
esac

exit 0


> wildfly-init-debian.sh fails on Ubuntu 15.04
> --------------------------------------------
>
>                 Key: WFLY-4570
>                 URL: https://issues.jboss.org/browse/WFLY-4570
>             Project: WildFly
>          Issue Type: Bug
>    Affects Versions: 9.0.0.Beta2, 9.0.0.CR1
>         Environment: Ubuntu 15.04, Oracle JDK_1.8.0_45-b14
>            Reporter: Dennis Gesker
>            Priority: Minor
>             Fix For: Awaiting Volunteers
>
>
> Init script "wildfly-init-debian.sh" fails on Ubuntu 15.04 but standalone.sh works fine.  Env is jdk_1.8.0_45-b14 and wildfly_9.0.0.Beta2. The error returned is:
> Failed to start wildfly.service: Unit wildfly.service failed to load: No such file or directory.
> Had no issue with the above script on Ubuntu 14.04 so guessing a change in Ubuntu ("Upstart" Maybe?) But, I'm far from an upstart or bash expert. bash -x seems to at least create the pid.



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the jboss-jira mailing list