Skip to content

Instantly share code, notes, and snippets.

@sidravic
Created March 19, 2015 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidravic/82244740acf420098f85 to your computer and use it in GitHub Desktop.
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
#!/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%
@sidravic
Copy link
Author

Might also be worth using for shutdown behavior.

def stop
   pid = File.read(PIDFILE) if File.exists?(LOGFILE)
 #  if pid
 #    puts  "stopping torquebox...."
 #    Process.kill('INT', pid.to_i)
 #    puts "Done."
 #  else
     system("kill -1 $(ps aux | grep standalone.sh | awk '{print $2}')")
    # system("kill -1 $(ps aux | grep torquebox | awk '{print $2}')")
     puts "torquebox stopped"
 #  end
end

@sidravic
Copy link
Author

#!/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

@sidravic
Copy link
Author

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