Sha256: 29559ff9f9007ffc7fc0e79272f6fcf692b1a5613652854ed507682eb5deed46

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

#!/usr/bin/env ruby1.9.1

# This script checks if the knjappserver is running - if not it forks and start it.
require "rubygems"
require "optparse"
Dir.chdir("#{File.dirname(__FILE__)}/../")

begin
	options = {
		:command => "ruby knjappserver_start.rb",
		:title => "knjappserver",
		:forking => true
	}
	OptionParser.new do |opts|
		opts.banner = "Usage: knjappserver.rb [options]"
		
		opts.on("--command=[cmd]", "Run verbosely.") do |cmd|
			options[:command] = cmd
		end
		
		opts.on("--title=[title]", "The title of the appserver that should be checked for.") do |title|
      options[:title] = title
		end
		
		opts.on("--forking=[forkval]", "If you want the script to fork or not.") do |forking|
      if forking.to_i >= 1
        options[:forking] = true
      else
        options[:forking] = false
      end
		end
		
		opts.on("--knjrbfw_path=[path]") do |path|
      options[:knjrbfw_path] = path
		end
	end.parse!
rescue OptionParser::InvalidOption => e
	print "#{e.message}\n"
	exit
end

if !options[:title]
  print "No title was given.\n"
  exit
end

if !options[:command]
  print "No command to execute was given.\n"
  exit
end

require "#{options[:knjrbfw_path]}knjrbfw"
require "knj/autoload"

tmpdir = "#{Knj::Os.tmpdir}/knjappserver"
tmppath = "#{tmpdir}/run_#{options[:title]}"
count = 0

if File.exists?(tmppath)
  pid = File.read(tmppath).to_s.strip
  count = Knj::Unix_proc.list("pids" => [pid]).length if pid.to_s.length > 0
end

exit if count > 0

if options[:forking]
  exec(options[:command]) if fork.nil?
else
  exec(options[:command])
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
knjappserver-0.0.29 bin/check_running.rb
knjappserver-0.0.28 bin/check_running.rb
knjappserver-0.0.26 bin/check_running.rb
knjappserver-0.0.25 bin/check_running.rb
knjappserver-0.0.24 bin/check_running.rb
knjappserver-0.0.23 bin/check_running.rb
knjappserver-0.0.22 bin/check_running.rb