Skip to content

Commit 7fd23aa

Browse files
Fixed non-sudo error handling when NGINX is not running when trying to stop
1 parent 24b07ad commit 7fd23aa

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ruby-nginx (1.0.3)
4+
ruby-nginx (1.0.4)
55
erb
66
thor
77
tty-command (~> 0.10, >= 0.10.1)

lib/ruby/nginx/commands/stop_nginx.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@ def initialize(sudo: false)
1616
def run
1717
super
1818
rescue Ruby::Nginx::StopError => e
19+
return if nginx_not_running_error?(e)
20+
1921
if @sudo
20-
# Nginx is not running - ignore.
21-
raise unless e.message.include?("invalid PID number")
22+
raise
2223
else
2324
# Elevate to sudo and try again.
2425
self.class.new(sudo: true).run
2526
end
2627
end
28+
29+
private
30+
31+
def nginx_not_running_error?(error)
32+
error.message.include?("invalid PID number") ||
33+
error.message.include?("No such process") ||
34+
error.message.include?("No such file or directory")
35+
end
2736
end
2837
end
2938
end

lib/ruby/nginx/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Ruby
44
module Nginx
5-
VERSION = "1.0.3"
5+
VERSION = "1.0.4"
66

77
Version = Gem::Version
88
end

0 commit comments

Comments
 (0)