Hi,
I created a simple init script for Fedora with sysconfig configuration for API. Both of these are placed in 'support/fedora' directory and it will be part of Fedora RPM.
Second patch allowing Thin to be run on background (this mode is used for initscript).
Howto test:
0. be sure, you have all necessary gems installed to run API 1. rake install[/usr/share/deltacloud-core, /usr/bin] 2. cp support/fedora/deltacloudd /etc/init.d 3. cp support/fedora/sysconfig_deltacloudd /etc/sysconfig/deltacloudd 4. /etc/init.d/deltacloudd start 5. navigate to http://localhost:3001 6. /etc/init.d/deltacloudd restart 7. /etc/init.d/deltacloudd stop
- Michal
--- server/bin/deltacloudd | 28 +++++++++++++++++++--------- 1 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd index a1c8f09..eda5c1b 100755 --- a/server/bin/deltacloudd +++ b/server/bin/deltacloudd @@ -27,6 +27,7 @@ BANNER end opts.on( '-e', '--env ENV', 'Environment (default: "development")') { |env| options[:env] = env } opts.on( '-h', '--help', '') { options[:help] = true } + opts.on( '-d', '--daemon', 'Run in background') { options[:daemon] = true } end
optparse.parse! @@ -46,14 +47,26 @@ ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
dirname="#{File.dirname(__FILE__)}/.."
+unless File.exists?(File.join(dirname, "config.ru")) + dirname = "/usr/share/deltacloud-core" if File.exists?("/usr/share/deltacloud-core/config.ru") +end + + argv_opts = ARGV.clone argv_opts << ['start'] unless Thin::Runner.commands.include?(options[0]) argv_opts << ['--address', ENV["API_HOST"] ] argv_opts << ['--port', ENV["API_PORT"] ] -argv_opts << ['--rackup', 'config.ru' ] +argv_opts << ['--rackup', "config.ru"] argv_opts << ['--chdir', dirname ] argv_opts << ['-e', options[:env] ] argv_opts << ['--threaded', '-D', '--stats', '/stats'] +if options[:daemon] + argv_opts << ['-d'] + argv_opts << ['--user', 'nobody'] + argv_opts << ['--pid', '/var/run/deltacloudd.pid'] + argv_opts << ['--log', '/var/log/deltacloudd.log'] + argv_opts << ['--tag', 'deltacloudd'] +end
argv_opts.flatten!
@@ -67,8 +80,10 @@ if options[:env] == "development" end end
-puts "Starting Deltacloud API :: #{ENV["API_DRIVER"]} :: http://#%7BENV%5B%22API_HOST%22%5D%7D:#%7BENV%5B%22API_PORT%22%5D%7D/api" -puts +unless options[:daemon] + puts "Starting Deltacloud API :: #{ENV["API_DRIVER"]} :: http://#%7BENV%5B%22API_HOST%22%5D%7D:#%7BENV%5B%22API_PORT%22%5D%7D/api" + puts +end
if use_rerun argv_opts.unshift "thin" @@ -79,10 +94,5 @@ if use_rerun rerun.join else thin = Thin::Runner.new(argv_opts) - - begin - thin.run! - rescue Exception => e - puts "ERROR: #{e.message}" - end + thin.run! end
--- server/support/fedora/deltacloudd | 106 +++++++++++++++++++++++++++ server/support/fedora/sysconfig_deltacloudd | 8 ++ 2 files changed, 114 insertions(+), 0 deletions(-) create mode 100755 server/support/fedora/deltacloudd create mode 100644 server/support/fedora/sysconfig_deltacloudd
diff --git a/server/support/fedora/deltacloudd b/server/support/fedora/deltacloudd new file mode 100755 index 0000000..ca9eb9d --- /dev/null +++ b/server/support/fedora/deltacloudd @@ -0,0 +1,106 @@ +#!/bin/sh +# +# deltacloud Deltacloud API server +# +# chkconfig: 2345 20 80 +# Description: Deltacloud protects your apps from cloud API \ +# changes and incompatibilities, so you can concentrate \ +# on managing cloud instances the way you want. + +### BEGIN INIT INFO +# Provides: deltacloudd +# Required-Start: $local_fs +# Required-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Deltacloud API server +# Description: Deltacloud protects your apps from cloud API \ +# changes and incompatibilities, so you can concentrate \ +# on managing cloud instances the way you want. +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +exec="/usr/bin/deltacloudd" +prog="deltacloudd" +config="/etc/sysconfig/deltacloudd" + +[ -e $config ] && . $config + +lockfile=/var/lock/subsys/deltacloudd +pidfile=/var/run/deltacloudd.pid + +start() { + [ -x $exec ] || exit 5 + [ -f $config ] || exit 6 + echo -n $"Starting $prog: " + daemon $exec -e $API_ENVIRONMENT -p $API_PORT -i $API_DRIVER -r $API_HOST -d + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping $prog: " + kill -3 `cat $pidfile` + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +reload() { + restart +} + +force_reload() { + restart +} + +rh_status() { + status $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + reload) + rh_status_q || exit 7 + $1 + ;; + force-reload) + force_reload + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" + exit 2 +esac +exit $? diff --git a/server/support/fedora/sysconfig_deltacloudd b/server/support/fedora/sysconfig_deltacloudd new file mode 100644 index 0000000..3f8fe91 --- /dev/null +++ b/server/support/fedora/sysconfig_deltacloudd @@ -0,0 +1,8 @@ +# Driver to use +API_DRIVER="mock" +# API port for accepting HTTP requests +API_PORT="3001" +# API host +API_HOST="localhost" +# Environment (production or development) +API_ENVIRONMENT="production"
On Wed, 2010-03-24 at 15:54 +0100, mfojtik@redhat.com wrote:
server/support/fedora/deltacloudd | 106 +++++++++++++++++++++++++++ server/support/fedora/sysconfig_deltacloudd | 8 ++ 2 files changed, 114 insertions(+), 0 deletions(-) create mode 100755 server/support/fedora/deltacloudd create mode 100644 server/support/fedora/sysconfig_deltacloudd
Initscript looks fine, one question about sysconfig setup:
diff --git a/server/support/fedora/sysconfig_deltacloudd b/server/support/fedora/sysconfig_deltacloudd new file mode 100644 index 0000000..3f8fe91 --- /dev/null +++ b/server/support/fedora/sysconfig_deltacloudd @@ -0,0 +1,8 @@ +# Driver to use +API_DRIVER="mock" +# API port for accepting HTTP requests +API_PORT="3001" +# API host +API_HOST="localhost" +# Environment (production or development) +API_ENVIRONMENT="production"
Is there really a point in configuring the environment ? I have a hard time believing that anybody wants to run a dev or test instance from the initscript.
David
On 25/03/10 15:40 -0700, David Lutterkort wrote:
On Wed, 2010-03-24 at 15:54 +0100, mfojtik@redhat.com wrote:
server/support/fedora/deltacloudd | 106 +++++++++++++++++++++++++++ server/support/fedora/sysconfig_deltacloudd | 8 ++ 2 files changed, 114 insertions(+), 0 deletions(-) create mode 100755 server/support/fedora/deltacloudd create mode 100644 server/support/fedora/sysconfig_deltacloudd
Initscript looks fine, one question about sysconfig setup:
diff --git a/server/support/fedora/sysconfig_deltacloudd b/server/support/fedora/sysconfig_deltacloudd new file mode 100644 index 0000000..3f8fe91 --- /dev/null +++ b/server/support/fedora/sysconfig_deltacloudd @@ -0,0 +1,8 @@ +# Driver to use +API_DRIVER="mock" +# API port for accepting HTTP requests +API_PORT="3001" +# API host +API_HOST="localhost" +# Environment (production or development) +API_ENVIRONMENT="production"
Is there really a point in configuring the environment ? I have a hard time believing that anybody wants to run a dev or test instance from the initscript.
Of course, there is no real point other than that user want's to have more details in log / raise errors / etc. This could be set to production.
Michal
On Fri, 2010-03-26 at 09:12 +0100, Michal Fojtik wrote:
On 25/03/10 15:40 -0700, David Lutterkort wrote:
On Wed, 2010-03-24 at 15:54 +0100, mfojtik@redhat.com wrote:
server/support/fedora/deltacloudd | 106 +++++++++++++++++++++++++++ server/support/fedora/sysconfig_deltacloudd | 8 ++ 2 files changed, 114 insertions(+), 0 deletions(-) create mode 100755 server/support/fedora/deltacloudd create mode 100644 server/support/fedora/sysconfig_deltacloudd
Initscript looks fine, one question about sysconfig setup:
diff --git a/server/support/fedora/sysconfig_deltacloudd b/server/support/fedora/sysconfig_deltacloudd new file mode 100644 index 0000000..3f8fe91 --- /dev/null +++ b/server/support/fedora/sysconfig_deltacloudd @@ -0,0 +1,8 @@ +# Driver to use +API_DRIVER="mock" +# API port for accepting HTTP requests +API_PORT="3001" +# API host +API_HOST="localhost" +# Environment (production or development) +API_ENVIRONMENT="production"
Is there really a point in configuring the environment ? I have a hard time believing that anybody wants to run a dev or test instance from the initscript.
Of course, there is no real point other than that user want's to have more details in log / raise errors / etc. This could be set to production.
Sure - for those though it would be better to have specific settings, rather than switching the environment wholesale. I don't think we need to add that for now; I'd only do that if we had a clear need for that.
David
On Wed, 2010-03-24 at 15:54 +0100, mfojtik@redhat.com wrote:
server/bin/deltacloudd | 28 +++++++++++++++++++--------- 1 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd index a1c8f09..eda5c1b 100755 --- a/server/bin/deltacloudd +++ b/server/bin/deltacloudd @@ -27,6 +27,7 @@ BANNER end opts.on( '-e', '--env ENV', 'Environment (default: "development")') { |env| options[:env] = env } opts.on( '-h', '--help', '') { options[:help] = true }
- opts.on( '-d', '--daemon', 'Run in background') { options[:daemon] = true }
end
optparse.parse! @@ -46,14 +47,26 @@ ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
dirname="#{File.dirname(__FILE__)}/.."
+unless File.exists?(File.join(dirname, "config.ru"))
- dirname = "/usr/share/deltacloud-core" if File.exists?("/usr/share/deltacloud-core/config.ru")
+end
Why even worry about /usr/share/deltacloud-core ? With that, we introduce a difference between gem and rpm installs that isn't really necessary, and can only lead to trouble (like the above)
I'd just assume that deltacloud-core is always run out of its gem location, so that you always know how to get to config.ru from deltacloudd.
argv_opts = ARGV.clone argv_opts << ['start'] unless Thin::Runner.commands.include?(options[0]) argv_opts << ['--address', ENV["API_HOST"] ] argv_opts << ['--port', ENV["API_PORT"] ] -argv_opts << ['--rackup', 'config.ru' ] +argv_opts << ['--rackup', "config.ru"]
Doesn't that need to take dirname into account ?
David
deltacloud-devel@lists.fedorahosted.org