This patch attempts to: * Clean up the connector startup script so it starts only one process (and stops/restarts more reliably) * fix the rackup file for proper daemonization
There are some first steps toward making it run as the aeolus user, but we are not quite there yet, so that will have to be a later patch. --- .../image_factory/image_factory_connector/Rakefile | 2 +- .../image_factory_connector/aeolus-connector.init | 94 +++++++++----------- .../image_factory_connector/lib/config.ru | 9 ++ .../image_factory_connector.rb | 6 -- 4 files changed, 52 insertions(+), 59 deletions(-)
diff --git a/services/image_factory/image_factory_connector/Rakefile b/services/image_factory/image_factory_connector/Rakefile index 9ae2773..eb2fe0a 100644 --- a/services/image_factory/image_factory_connector/Rakefile +++ b/services/image_factory/image_factory_connector/Rakefile @@ -31,7 +31,7 @@ RPM_SPEC = "rubygem-image_factory_connector.spec"
spec = Gem::Specification.new do |s| s.name = 'image_factory_connector' - s.version = '0.0.1' + s.version = '0.0.2' s.has_rdoc = true #s.extra_rdoc_files = ['README', 'LICENSE'] s.summary = 'Sinatra microapp to talk to Aeolus Image Factory QMF console' diff --git a/services/image_factory/image_factory_connector/aeolus-connector.init b/services/image_factory/image_factory_connector/aeolus-connector.init index 02fced4..9c8a9bb 100755 --- a/services/image_factory/image_factory_connector/aeolus-connector.init +++ b/services/image_factory/image_factory_connector/aeolus-connector.init @@ -1,61 +1,58 @@ #!/bin/bash # -# aeolus-connector startup script for aeolus-connector +# aeolus-connector Start up the aeolus-connector daemon # # chkconfig: 2345 97 03 -# description: aeolus-connector is a microapp to talk to -# Aeolus Image Factory QMF console +# description: aeolus-connector is a microapp to talk to \ +# Aeolus Image Factory QMF console + +# source function library +. /etc/rc.d/init.d/functions
RETVAL=0 prog="aeolus-connector" -exec=/usr/bin/image_factory_connector -lockfile=/var/lock/subsys/aeolus-connector +lockfile=/var/lock/subsys/$prog +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
-# Source function library. -. /etc/rc.d/init.d/functions +gemdir=$( ruby -rubygems -e 'puts Gem::dir' ) +CONNECTOR_ENV="${CONNECTOR_ENV:-production}" +RACKUP_FILE="${RACKUP_FILE:-$gemdir/gems/image_factory_connector-0.0.2/lib/config.ru}" +RUN_DIR="${RUN_DIR:-$gemdir/gems/image_factory_connector-0.0.2/bin}" +LOG="${THIN_LOG:-/var/log/aeolus-connector.log}" +PID="${THIN_PID:-/var/run/aeolus-connector.pid}" +AEOLUS_USER="${AEOLUS_USER:-aeolus}" +PORT="${PORT:-2003}" +ADDR=127.0.0.1
-port=2003 -logfile=/var/log/aeolus-conductor/aeolus-connector.log -[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog +CONNECTOR=image_factory_connector
start() { - if [ $UID -ne 0 ] ; then - echo "User has insufficient privilege." - exit 1 - fi - if [ -e $lockfile ] ; then - status image_factory_connector > /dev/null 2>&1 - retval=$? - if [ $retval == 0 ] ; then - echo $prog is currently running - exit 2 - fi - fi - [ -x $exec ] || exit 3 echo -n $"Starting $prog: " - daemon $exec -p $port start >> $logfile 2>&1 & - retval=$? - if [ $retval -eq 0 ] ; then - touch $lockfile - echo_success - echo - exit 0 + if [ -f $PID ] && checkpid `cat $PID` ; then + echo_failure + echo + echo -n $"$prog is already running" + exit 1 + fi + + $CONNECTOR -l $LOG -P $PID -a $ADDR -e $CONNECTOR_ENV --chdir $RUN_DIR -d -p $PORT start + # FIXME: long term, the version below is what we want to run, but at this point have not been able to get it working + #daemon --user $AEOLUS_USER $CONNECTOR -l $LOG -P $PID -a $ADDR -e $ENV -p $PORT --chdir $RUN_DIR -d start + RETVAL=$? + if [ $RETVAL -eq 0 ] ; then + echo_success + echo else - echo_failure - echo - exit 3 + echo_failure + echo fi }
stop() { - if [ $UID -ne 0 ] ; then - echo "User has insufficient privilege." - exit 4 - fi echo -n $"Stopping $prog: " - killproc image_factory_connector - retval=$? - if [ $retval -eq 0 ] && rm -f $lockfile ; then + killproc -p $PID $CONNECTOR + RETVAL=$? + if [ $RETVAL -eq 0 ] && rm -f $lockfile ; then echo_success echo else @@ -63,15 +60,6 @@ stop() { fi }
-restart() { - stop - start -} - -rh_status() { - status -l $lockfile image_factory_connector -} - case "$1" in start) $1 @@ -80,14 +68,16 @@ case "$1" in $1 ;; restart) - $1 + stop + start ;; status) - rh_status + status -p $PID $CONNECTOR + RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 2 esac -exit $?
+exit $RETVAL diff --git a/services/image_factory/image_factory_connector/lib/config.ru b/services/image_factory/image_factory_connector/lib/config.ru index 82a1a3d..ad3291a 100644 --- a/services/image_factory/image_factory_connector/lib/config.ru +++ b/services/image_factory/image_factory_connector/lib/config.ru @@ -1,4 +1,13 @@ $: << File.expand_path(File.dirname(__FILE__) + '.') require 'image_factory_connector'
+@l = Logger.new(STDOUT) +@l.level = Logger::DEBUG + +@console = ImageFactoryConsole.new({:handler=>FactoryRestHandler.new(@l), :logger =>@l}) +@console.start + run ImageFactoryConnector + +ImageFactoryConnector.set :console, @console +ImageFactoryConnector.set :logger, @l diff --git a/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb b/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb index 2ecbd58..f17b3e2 100644 --- a/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb +++ b/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb @@ -29,12 +29,6 @@ class ImageFactoryConnector < Sinatra::Base set :port, 2003 set :app_file, __FILE__ set :views, File.dirname(__FILE__) + '/views' - @l = Logger.new(STDOUT) - @l.level = Logger::DEBUG - @console = ImageFactoryConsole.new({:handler=>FactoryRestHandler.new(@l), :logger =>@l}) - @console.start - set :console, @console - set :logger, @l end
# TODO: add validation for required params not being passed at all,
On 04/13/2011 04:43 PM, Jason Guiditta wrote:
This patch attempts to:
- Clean up the connector startup script so it starts only one process (and stops/restarts more reliably)
- fix the rackup file for proper daemonization
There are some first steps toward making it run as the aeolus user, but we are not quite there yet, so that will have to be a later patch.
.../image_factory/image_factory_connector/Rakefile | 2 +- .../image_factory_connector/aeolus-connector.init | 94 +++++++++----------- .../image_factory_connector/lib/config.ru | 9 ++ .../image_factory_connector.rb | 6 -- 4 files changed, 52 insertions(+), 59 deletions(-)
diff --git a/services/image_factory/image_factory_connector/Rakefile b/services/image_factory/image_factory_connector/Rakefile index 9ae2773..eb2fe0a 100644 --- a/services/image_factory/image_factory_connector/Rakefile +++ b/services/image_factory/image_factory_connector/Rakefile @@ -31,7 +31,7 @@ RPM_SPEC = "rubygem-image_factory_connector.spec"
spec = Gem::Specification.new do |s| s.name = 'image_factory_connector'
- s.version = '0.0.1'
- s.version = '0.0.2' s.has_rdoc = true #s.extra_rdoc_files = ['README', 'LICENSE'] s.summary = 'Sinatra microapp to talk to Aeolus Image Factory QMF console'
diff --git a/services/image_factory/image_factory_connector/aeolus-connector.init b/services/image_factory/image_factory_connector/aeolus-connector.init index 02fced4..9c8a9bb 100755 --- a/services/image_factory/image_factory_connector/aeolus-connector.init +++ b/services/image_factory/image_factory_connector/aeolus-connector.init @@ -1,61 +1,58 @@ #!/bin/bash # -# aeolus-connector startup script for aeolus-connector +# aeolus-connector Start up the aeolus-connector daemon # # chkconfig: 2345 97 03 -# description: aeolus-connector is a microapp to talk to -# Aeolus Image Factory QMF console +# description: aeolus-connector is a microapp to talk to \ +# Aeolus Image Factory QMF console
+# source function library +. /etc/rc.d/init.d/functions
RETVAL=0 prog="aeolus-connector" -exec=/usr/bin/image_factory_connector -lockfile=/var/lock/subsys/aeolus-connector +lockfile=/var/lock/subsys/$prog +[ -e /etc/sysconfig/$prog ]&& . /etc/sysconfig/$prog
-# Source function library. -. /etc/rc.d/init.d/functions +gemdir=$( ruby -rubygems -e 'puts Gem::dir' ) +CONNECTOR_ENV="${CONNECTOR_ENV:-production}" +RACKUP_FILE="${RACKUP_FILE:-$gemdir/gems/image_factory_connector-0.0.2/lib/config.ru}" +RUN_DIR="${RUN_DIR:-$gemdir/gems/image_factory_connector-0.0.2/bin}" +LOG="${THIN_LOG:-/var/log/aeolus-connector.log}" +PID="${THIN_PID:-/var/run/aeolus-connector.pid}" +AEOLUS_USER="${AEOLUS_USER:-aeolus}" +PORT="${PORT:-2003}" +ADDR=127.0.0.1
-port=2003 -logfile=/var/log/aeolus-conductor/aeolus-connector.log -[ -e /etc/sysconfig/$prog ]&& . /etc/sysconfig/$prog +CONNECTOR=image_factory_connector
start() {
- if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 1
- fi
- if [ -e $lockfile ] ; then
status image_factory_connector> /dev/null 2>&1
retval=$?
if [ $retval == 0 ] ; then
echo $prog is currently running
exit 2
fi
- fi
- [ -x $exec ] || exit 3 echo -n $"Starting $prog: "
- daemon $exec -p $port start>> $logfile 2>&1&
- retval=$?
- if [ $retval -eq 0 ] ; then
touch $lockfile
echo_success
echo
exit 0
- if [ -f $PID ]&& checkpid `cat $PID` ; then
echo_failure
echo
echo -n $"$prog is already running"
exit 1
- fi
- $CONNECTOR -l $LOG -P $PID -a $ADDR -e $CONNECTOR_ENV --chdir $RUN_DIR -d -p $PORT start
- # FIXME: long term, the version below is what we want to run, but at this point have not been able to get it working
- #daemon --user $AEOLUS_USER $CONNECTOR -l $LOG -P $PID -a $ADDR -e $ENV -p $PORT --chdir $RUN_DIR -d start
- RETVAL=$?
- if [ $RETVAL -eq 0 ] ; then
echo_success
echo else
echo_failure
echo
exit 3
echo_failure
echo fi
}
stop() {
- if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
- fi echo -n $"Stopping $prog: "
- killproc image_factory_connector
- retval=$?
- if [ $retval -eq 0 ]&& rm -f $lockfile ; then
- killproc -p $PID $CONNECTOR
- RETVAL=$?
- if [ $RETVAL -eq 0 ]&& rm -f $lockfile ; then echo_success echo else
@@ -63,15 +60,6 @@ stop() { fi }
-restart() {
- stop
- start
-}
-rh_status() {
- status -l $lockfile image_factory_connector
-}
- case "$1" in start) $1
@@ -80,14 +68,16 @@ case "$1" in $1 ;; restart)
$1
stop
start ;; status)
rh_status
status -p $PID $CONNECTOR
esacRETVAL=$? ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 2
-exit $?
+exit $RETVAL diff --git a/services/image_factory/image_factory_connector/lib/config.ru b/services/image_factory/image_factory_connector/lib/config.ru index 82a1a3d..ad3291a 100644 --- a/services/image_factory/image_factory_connector/lib/config.ru +++ b/services/image_factory/image_factory_connector/lib/config.ru @@ -1,4 +1,13 @@ $:<< File.expand_path(File.dirname(__FILE__) + '.') require 'image_factory_connector'
+@l = Logger.new(STDOUT) +@l.level = Logger::DEBUG
+@console = ImageFactoryConsole.new({:handler=>FactoryRestHandler.new(@l), :logger =>@l}) +@console.start
- run ImageFactoryConnector
+ImageFactoryConnector.set :console, @console +ImageFactoryConnector.set :logger, @l diff --git a/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb b/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb index 2ecbd58..f17b3e2 100644 --- a/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb +++ b/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb @@ -29,12 +29,6 @@ class ImageFactoryConnector< Sinatra::Base set :port, 2003 set :app_file, __FILE__ set :views, File.dirname(__FILE__) + '/views'
@l = Logger.new(STDOUT)
@l.level = Logger::DEBUG
@console = ImageFactoryConsole.new({:handler=>FactoryRestHandler.new(@l), :logger =>@l})
@console.start
set :console, @console
set :logger, @l end
# TODO: add validation for required params not being passed at all,
Conditional ACK.
Need to update the Version in rubygem-image_factory_connector.spec, after applying that fix locally I was able to start, status, stop, restart and confirm that the pid file seems correct & logging is occurring in the expected location.
Additionally, I created a template and was able to initiate a build and see events in both the imagefactory & aeolus-connector log.
aeolus-devel@lists.fedorahosted.org