我在 Ubuntu 12.04 上有一个用于 JBoss 的非常基本的 systemd 脚本。我可以通过“sudo service jboss start”或“sudo /etc/init.d/jboss start”成功运行它。我不能让这个和厨师一起工作。我原以为它会很简单:
service "jboss" do
action [ :start ]
end
但是不行。我试过了:
service "jboss" do
supports :start => true, :stop => true, :status => false
action [ :start, :enable ]
start_command "sudo /etc/init.d/jboss start"
end
以及不同的排列。
感谢您的帮助,请参阅下面的我的 systemd 脚本。
#!/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
更新:
感谢那些回答的人。我设法取得了一些进展。我从 OpsCode 下载了 JBoss Chef 食谱:http: //community.opscode.com/cookbooks/jboss
结果发现我的脚本中没有设置 JAVA_HOME 环境变量。我现在正在使用 OpsCode 的启动脚本。JBoss 现在从配方开始:
service "jboss" do
action [ :enable, :start ]
end
但是厨师挂在这条线上。我认为它正在等待 JBoss “完成”,但由于它应该是一项服务,它应该是持久的。如果我通过 SSH 进入实例并杀死 JBoss,则 Chef 配方成功完成。我怎样才能让厨师食谱正常结束?有关我更新的 systemd 脚本,请参见下文。
#!/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