Skip to content

Instantly share code, notes, and snippets.

@purcell
Created May 12, 2013 18:26
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 purcell/5564449 to your computer and use it in GitHub Desktop.
Save purcell/5564449 to your computer and use it in GitHub Desktop.
Java programs packaged up with Tanuki Software's "Wrapper" software are horribly unreliable when run via init.d scripts. Luckily it's easy to make such a program reliably runnable with runit or daemontools.
#!/usr/bin/env ruby
wrapper_conf = "wrapper.conf"
props = ARGF.readlines.reduce(Hash.new) do |info, line|
info[$1] = $2 if line =~ /^wrapper\.(.+?)\s*=\s*(.*)\s*$/
info
end
command = [props["java.command"]]
n = 1
while v = props["java.additional.%d" % n]
command << v
n += 1
end
if initmem = props["java.initmemory"]
command << "-Xms" + initmem + "m"
end
if maxmem = props["java.maxmemory"]
command << "-Xmx" + maxmem + "m"
end
classpath = []
n = 1
while v = props["java.classpath.%d" % n]
classpath << Dir.glob(v)
n += 1
end
command << "-classpath" << classpath.flatten.join(":")
n = 1
while v = props["app.parameter.%d" % n]
command << v
n += 1
end
puts command.inspect
exec(*command)
#!/bin/sh -e
THISDIR=$PWD
exec 2>&1
cd /opt/sonar/bin/linux-x86-64
exec chpst -u sonar $THISDIR/java-wrapper-runit ../../conf/wrapper.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment