Start JBoss 7 as a service on Linux

后端 未结 12 2008
闹比i
闹比i 2020-12-12 11:54

Previous versions of JBoss included a scripts (like jboss_init_redhat.sh) that could be copied to /etc/init.d in order to add it as a service - so it would star

12条回答
  •  不知归路
    2020-12-12 12:29

    The answer marked as correct here did not work for me. On restart, you get a security error related to the usage of sudo, stating, "sorry, you must have a tty to run sudo." Further research revealed that disabling the sudo tty restriction could cause plain text exposure of passwords, so that's no good.

    Here's what I ended up with and it works fine for me:

    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides:          jboss
    # Required-Start:    $local_fs $remote_fs $network $syslog
    # Required-Stop:     $local_fs $remote_fs $network $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start/Stop JBoss AS v7.0.0
    ### END INIT INFO
    #
    #source some script files in order to set and export environmental variables
    #as well as add the appropriate executables to $PATH
    [ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
    [ -r /etc/profile.d/jboss.sh ] && . /etc/profile.d/jboss.sh
    
    case "$1" in
        start)
            echo "Starting JBoss AS 7.0.0"
            su --session-command "${JBOSS_HOME}/bin/standalone.sh >& /dev/null &" jboss
        ;;
        stop)
            echo "Stopping JBoss AS 7.0.0"
            su --session-command "${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown" jboss
        ;;
        *)
            echo "Usage: /etc/init.d/jboss {start|stop}"
            exit 1
        ;;
    esac
    
    exit 0
    

提交回复
热议问题