Skip to content

Instantly share code, notes, and snippets.

@smeevil
Created December 17, 2009 13:41
Show Gist options
  • Save smeevil/258744 to your computer and use it in GitHub Desktop.
Save smeevil/258744 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
@exec="red5.sh"
@name="Red 5"
@match="/var/red5/boot.jar"
@kill_sig="-9"
@sleep=5
@pidfile=File.expand_path(File.join(File.dirname(__FILE__), "pid", "#{@exec}.pid"))
@path=File.expand_path(File.join(File.dirname(__FILE__)))
def start
print "starting #{@name}..."
STDOUT.flush
system("#{@path}/#{@exec} & echo $! > #{@pidfile}")
puts " [done]"
end
def stop
if pid_present?
print "stopping #{@name}..."
STDOUT.flush
`kill #{@kill_sig} #{@pid}`
sleep @sleep
puts " [done]"
else
puts "#{@name} appears not to be running...(pid not found)"
end
end
def restart
stop
start
puts "#{@name} restarted !"
end
def pid_present?
puts "checking for #{@pidfile}"
if File.exists?(@pidfile)
@pid=File.read(@pidfile).chomp
puts "pid of #{@name} : #{@pid}"
@check=`ps #{@pid}`.split("\n").last
File.delete(@pidfile)
return @check=~/#{@match}/
else
return false
end
end
case ARGV[0]
when "start" then start
when "stop" then stop
when "restart" then restart
else
puts "call with start | stop | restart"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment