4 exit
if fork
# Parent exits, child continues.
5 Process
.setsid
# Become session leader.
6 exit
if fork
# Zap session leader. See [1].
7 Dir
.chdir
"/" # Release old working directory.
8 File
.umask
0000 # Ensure sensible umask. Adjust as needed.
9 STDIN.reopen
"/dev/null" # Free file descriptors and
10 STDOUT.reopen
"/dev/null", "a" # point them somewhere sensible.
11 STDERR.reopen
STDOUT # STDOUT/ERR should better go to a logfile.
16 :command => File
.expand_path(RAILS_ROOT
+ '/script/process/spawner'),
20 ARGV.options
do |opts
|
21 opts
.banner
= "Usage: spinner [options]"
27 The spinner is a protection loop for the spawner, which will attempt to restart any FCGI processes
28 that might have been exited or outright crashed. It's a brute-force attempt that'll just try
29 to run the spawner every X number of seconds, so it does pose a light load on the server.
32 spinner # attempts to run the spawner with default settings every second with output on the terminal
33 spinner -i 3 -d # only run the spawner every 3 seconds and detach from the terminal to become a daemon
34 spinner -c '/path/to/app/script/process/spawner -p 9000 -i 10' -d # using custom spawner
39 opts
.on("-c", "--command=path", String
) { |v
| OPTIONS
[:command] = v
}
40 opts
.on("-i", "--interval=seconds", Float
) { |v
| OPTIONS
[:interval] = v
}
41 opts
.on("-d", "--daemon") { |v
| OPTIONS
[:daemon] = v
}
45 opts
.on("-h", "--help", "Show this help message.") { puts opts
; exit
}
50 daemonize
if OPTIONS
[:daemon]
52 trap(OPTIONS
[:daemon] ? "TERM" : "INT") { exit
}
55 system(OPTIONS
[:command])
56 sleep(OPTIONS
[:interval])