Script to get upstart out of a start/killed state (http://heh.fi/tmp/workaround-upstart-snafu)
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 ruby1.8 | |
class Workaround | |
def initialize target_pid | |
@target_pid = target_pid | |
first_child | |
end | |
def first_child | |
pid = fork do | |
Process.setsid | |
rio, wio = IO.pipe | |
# Keep rio open | |
until second_child rio, wio | |
print "\e[A" | |
end | |
end | |
Process.wait pid | |
end | |
def second_child parent_rio, parent_wio | |
rio, wio = IO.pipe | |
pid = fork do | |
rio.close | |
parent_wio.close | |
puts "%20.20s" % Process.pid | |
if Process.pid == @target_pid | |
wio << 'a' | |
wio.close | |
parent_rio.read | |
end | |
end | |
wio.close | |
begin | |
if rio.read == 'a' | |
true | |
else | |
Process.wait pid | |
false | |
end | |
ensure | |
rio.close | |
end | |
end | |
end | |
if $0 == __FILE__ | |
pid = ARGV.shift | |
raise "USAGE: #{$0} pid" if pid.nil? | |
Workaround.new Integer pid | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment