Module: Kanrisuru::Nginx::Service
- Extended by:
- OsPackage::Define
- Defined in:
- lib/kanrisuru/nginx/service.rb
Instance Method Summary collapse
- #master_pid ⇒ Object
- #master_process ⇒ Object
- #reload(opts = {}) ⇒ Object
- #restart(opts = {}) ⇒ Object
- #running? ⇒ Boolean
- #start(opts = {}) ⇒ Object
- #stop ⇒ Object
- #test(opts = {}) ⇒ Object
- #worker_processess ⇒ Object
Instance Method Details
#master_pid ⇒ Object
82 83 84 85 86 87 |
# File 'lib/kanrisuru/nginx/service.rb', line 82 def master_pid process = master_process return unless process.instance_of?(Kanrisuru::Core::System::ProcessInfo) process.pid end |
#master_process ⇒ Object
75 76 77 78 79 80 |
# File 'lib/kanrisuru/nginx/service.rb', line 75 def master_process result = @host.ps return result if result.failure? result.find { |process| process.command.include?('nginx: master') } end |
#reload(opts = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/kanrisuru/nginx/service.rb', line 57 def reload(opts = {}) command = Kanrisuru::Command.new('nginx') command.append_arg('-c', opts[:config]) command.append_arg('-s', 'reload') @host.execute_shell(command) Kanrisuru::Result.new(command) end |
#restart(opts = {}) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/kanrisuru/nginx/service.rb', line 48 def restart(opts = {}) return false unless running? result = stop return false unless result.success? start(opts) end |
#running? ⇒ Boolean
67 68 69 70 71 72 73 |
# File 'lib/kanrisuru/nginx/service.rb', line 67 def running? process = master_process return false if !process || process.instance_of?(Kanrisuru::Result) process.respond_to?(:pid) && process.pid >= 0 end |
#start(opts = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/kanrisuru/nginx/service.rb', line 20 def start(opts = {}) command = Kanrisuru::Command.new('nginx') command.append_arg('-c', opts[:config]) @host.execute_shell(command) Kanrisuru::Result.new(command) end |
#stop ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/kanrisuru/nginx/service.rb', line 39 def stop command = Kanrisuru::Command.new('nginx') command.append_arg('-s', 'stop') @host.execute_shell(command) Kanrisuru::Result.new(command) end |
#test(opts = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/kanrisuru/nginx/service.rb', line 29 def test(opts = {}) command = Kanrisuru::Command.new('nginx') command.append_arg('-c', opts[:config]) command.append_flag('-t') @host.execute_shell(command) Kanrisuru::Result.new(command) end |
#worker_processess ⇒ Object
89 90 91 92 93 94 |
# File 'lib/kanrisuru/nginx/service.rb', line 89 def worker_processess result = @host.ps return result if result.failure? result.select { |process| process.command.include?('nginx: worker') } end |