Skip to content

Instantly share code, notes, and snippets.

@mneedham
Created September 29, 2012 09:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mneedham/3803604 to your computer and use it in GitHub Desktop.
Save mneedham/3803604 to your computer and use it in GitHub Desktop.
Script to get upstart out of a start/killed state (http://heh.fi/tmp/workaround-upstart-snafu)
#!/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
@ion1
Copy link

ion1 commented Sep 29, 2012

Hi,

I moved the script to a GitHub repo and added a description and a copyright notice while I was at it: https://github.com/ion1/workaround-upstart-snafu

The original URL (http://heh.fi/tmp/workaround-upstart-snafu) now redirects to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment