33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/sneakers/cli.rb', line 33
def work(workers = "")
opts = {
:daemonize => !!options[:daemonize]
}
opts[:log] = options[:log] || (opts[:daemonize] ? 'sneakers.log' : STDOUT)
opts[:pid_path] = options[:pid_path] if options[:pid_path]
if opts[:daemonize]
puts "*** DEPRACATED: self-daemonization '--daemonize' is considered a bad practice, which is why this feature will be removed in future versions. Please run Sneakers in front, and use things like upstart, systemd, or supervisor to manage it as a daemon."
end
Sneakers.configure(opts)
require_boot File.expand_path(options[:require]) if options[:require]
if workers.empty?
workers = Sneakers::Worker::Classes
else
workers, missing_workers = Sneakers::Utils.parse_workers(workers)
end
unless missing_workers.nil? || missing_workers.empty?
say "Missing workers: #{missing_workers.join(', ')}" if missing_workers
say "Did you `require` properly?"
return
end
if workers.empty?
say " Error: No workers found.\n Please require your worker classes before specifying in CLI\n\n $ sneakers work FooWorker\n ^- require this in your code\n\n EOF\n return\n end\n\n r = Sneakers::Runner.new(workers)\n\n pid = Sneakers::CONFIG[:pid_path]\n\n say SNEAKERS\n say \"Workers ....: \#{em workers.join(', ')}\"\n say \"Log ........: \#{em (Sneakers::CONFIG[:log] == STDOUT ? 'Console' : Sneakers::CONFIG[:log]) }\"\n say \"PID ........: \#{em pid}\"\n say \"\"\n say (\" \"*31)+\"Process control\"\n say \"=\"*80\n say \"Stop (nicely) ..............: kill -SIGTERM `cat \#{pid}`\"\n say \"Stop (immediate) ...........: kill -SIGQUIT `cat \#{pid}`\"\n say \"Restart (nicely) ...........: kill -SIGUSR1 `cat \#{pid}`\"\n say \"Restart (immediate) ........: kill -SIGHUP `cat \#{pid}`\"\n say \"Reconfigure ................: kill -SIGUSR2 `cat \#{pid}`\"\n say \"Scale workers ..............: reconfigure, then restart\"\n say \"=\"*80\n say \"\"\n\n if options[:debug]\n say \"==== configuration ===\"\n say Sneakers::CONFIG.inspect\n say \"======================\"\n end\n\n r.run\nend\n"
|