Created
May 12, 2013 18:26
-
-
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.
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 | |
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) |
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
#!/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