I have a very basic systemd script for JBoss on Ubuntu 12.04. I am able to run it successfully via "sudo service jboss start" OR "sudo /etc/init.d/jboss start". I can't get this to work with Chef. I would have thought it would be as simple as:

service "jboss" do
    action [ :start ]
end

But no go. I've tried:

service "jboss" do
    supports :start => true, :stop => true, :status => false
    action [ :start, :enable ]
    start_command "sudo /etc/init.d/jboss start"
end

and different permutations as well.

Thanks for your help, and see below for my systemd script.

#!/bin/bash
### 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
# Usage: this file neeed to be renamed jboss
### 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.1.1"
        cd /home/jboss/jboss-as-7.1.1.Final/bin/
        sudo -u jboss ./standalone.sh &
    ;;
    stop)
        echo "Stopping JBoss AS 7.1.1"
        sudo -u jboss /home/jboss/jboss-as-7.1.1.Final/bin/jboss-cli.sh --connect command=:shutdown
        #JBOSS_PID=$(ps -ef | grep jboss-as-7.1.1.Final | grep -v grep | awk '{print $2}')
        #kill -15 $JBOSS_PID
        #echo "Sig term sent"
        #echo "Terminating all ml_process"
        #pkill -9 ml_server
    ;;
    *)
        echo "Usage: /etc/init.d/jboss {start|stop}"
        exit 1
    ;;
esac

UPDATE:

Thanks to those who replied. I managed to make a bit of progress. I downloaded the JBoss Chef recipe from OpsCode: http://community.opscode.com/cookbooks/jboss

Turns out that the JAVA_HOME environmental variable wasn't being set in my script. I'm now using the startup script from OpsCode. JBoss now starts with the recipe:

service "jboss" do
  action [ :enable, :start ]
end

But Chef hangs on this line. I think it's waiting for JBoss to "finish", but since it's supposed to be a service it should persistent. If I SSH into the instance and kill JBoss, the Chef recipe completes successfully. How can I get the Chef recipe to end normally? See below for my updated systemd script.

#!/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


export JAVA_HOME=/usr/lib/jvm/java-7-oracle

#define where jboss is - this is the directory containing directories log, bin, conf etc
export JBOSS_HOME=${JBOSS_HOME:-"/home/jboss/jboss-as-7.1.1.Final"}

#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
export JBOSS_USER=${JBOSS_USER:-"jboss"}

#make sure java is in your path
JAVAPTH=${JAVAPTH:-"$JAVA_HOME/bin/java"}
export PATH=$PATH:$JAVAPTH

#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"
        cd /home/jboss/jboss-as-7.1.1.Final/bin/
        sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh
    ;;
    stop)
        echo "Stopping JBoss AS 7.0.0"
        sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect
    command=:shutdown
    ;;
    *)
        echo "Usage: /etc/init.d/jboss {start|stop}"
        exit 1
    ;;
esac

exit 0
有帮助吗?

解决方案

After much frustration, I was able to get Chef to launch and persist JBoss with the following recipe:

bash "Start JBoss" do
    cwd "/home/jboss/jboss-as-7.1.1.Final/bin"
    code <<-EOH
    sudo -u jboss start-stop-daemon --start --quiet --background --chdir /home/jboss/jboss-as-7.1.1.Final/bin --chuid jboss --exec /home/jboss/jboss-as-7.1.1.Final/bin/standalone.sh
    EOH
end

Many thanks to everyone who helped and to whomever wrote this: https://github.com/octo-technology/master-chef/blob/master/cookbooks/jboss/templates/default/jboss-as-standalone.sh.erb

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top