Created
March 19, 2015 08:47
-
-
Save sidravic/82244740acf420098f85 to your computer and use it in GitHub Desktop.
A basic init script to start and stop torquebox. Copy this script to the /etc/init.d/ folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "fileutils" | |
puts "Using system RVM" | |
#system("/bin/bash --login && rvm use system") | |
puts "Initializing PID and Log files" | |
PIDFOLDER = "/opt/pids" | |
PIDFILE = "/opt/pids/torquebox.pid" | |
LOGFILE = "/var/log/torquebox/torquebox.log" | |
FileUtils.mkdir_p(PIDFOLDER) unless Dir.exists?(PIDFILE) | |
def run_torquebox | |
puts "Executing run command" | |
system("/opt/torquebox-3.1.1/jboss/bin/standalone.sh >> /var/log/torquebox/torquebox.log 2>&1") | |
end | |
def start | |
puts "Starting torquebox..." | |
pid = Process.fork do | |
run_torquebox | |
end | |
Process.detach(pid) | |
File.open(PIDFILE, 'w') do |f| | |
f.write(pid.to_s) | |
end | |
puts "Started torquebox." | |
end | |
def stop | |
pid = File.read(PIDFILE) if File.exists?(LOGFILE) | |
if pid | |
puts "stopping torquebox...." | |
Process.kill('INT', pid.to_i) | |
puts "torquebox stopped" | |
end | |
end | |
puts "Calling start" | |
#start() | |
command = ARGV[0] | |
case command | |
when 'start' | |
start() | |
when 'stop' | |
stop() | |
when 'restart' | |
stop() | |
start() | |
else | |
puts "Usage: sudo /etc/init.d/torquebox <start|stop|restart>" | |
end | |
51,1 96% |
#!/usr/bin/env ruby
require "fileutils"
puts "Using system RVM"
#system("/bin/bash --login && rvm use system")
puts "Initializing PID and Log files"
PIDFOLDER = "/opt/pids"
PIDFILE = "/opt/pids/torquebox.pid"
LOGFILE = "/var/log/torquebox/torquebox.log"
FileUtils.mkdir_p(PIDFOLDER) unless Dir.exists?(PIDFILE)
def run_torquebox
puts "Executing run command"
system("/opt/torquebox-3.1.1/jboss/bin/standalone.sh >> /var/log/torquebox/torquebox.log 2>&1")
end
def start
puts "Starting torquebox..."
pid = Process.fork do
run_torquebox
end
Process.detach(pid)
File.open(PIDFILE, 'w') do |f|
f.write(pid.to_s)
end
puts "Started torquebox."
end
def stop
system("kill -1 $(ps aux | grep standalone.sh | awk '{print $2}')")
puts "torquebox stopped"
end
puts "Calling start"
command = ARGV[0]
case command
when 'start'
start()
when 'stop'
stop()
when 'restart'
stop()
start()
else
puts "Usage: sudo /etc/init.d/torquebox <start|stop|restart>"
end
system("kill -1 $(ps aux | grep standalone | awk '{print $2}')")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Might also be worth using for shutdown behavior.