Class: Nginx::Server
- Inherits:
-
Object
- Object
- Nginx::Server
- Defined in:
- lib/nginx/server.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
Class Method Summary collapse
Instance Method Summary collapse
- #access_log ⇒ Object
- #error_log ⇒ Object
-
#initialize(string, dir: "/tmp/nginx.#{Process.pid}.#{SecureRandom.uuid}", **params) ⇒ Server
constructor
A new instance of Server.
- #pid ⇒ Object
- #pidfile ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(string, dir: "/tmp/nginx.#{Process.pid}.#{SecureRandom.uuid}", **params) ⇒ Server
Returns a new instance of Server.
45 46 47 48 49 50 |
# File 'lib/nginx/server.rb', line 45 def initialize string, dir: "/tmp/nginx.#{Process.pid}.#{SecureRandom.uuid}", **params @dir = Pathname dir; @dir.mkpath set_params params create_config string end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
52 53 54 |
# File 'lib/nginx/server.rb', line 52 def dir @dir end |
Class Method Details
.from_file(file, **all) ⇒ Object
41 42 43 |
# File 'lib/nginx/server.rb', line 41 def self.from_file file, **all new (IO.read file), **all end |
Instance Method Details
#access_log ⇒ Object
70 71 72 |
# File 'lib/nginx/server.rb', line 70 def access_log 'access.log' end |
#error_log ⇒ Object
66 67 68 |
# File 'lib/nginx/server.rb', line 66 def error_log 'error.log' end |
#pid ⇒ Object
74 75 76 |
# File 'lib/nginx/server.rb', line 74 def pid IO.read(pidfile).to_i end |
#pidfile ⇒ Object
78 79 80 |
# File 'lib/nginx/server.rb', line 78 def pidfile 'nginx.pid' end |
#start ⇒ Object
54 55 56 57 58 59 |
# File 'lib/nginx/server.rb', line 54 def start @nginx_pid = suppress_output do spawn "nginx -c nginx.conf -p #{@dir} -g 'daemon off;'" end; at_exit { stop } @nginx_pid end |
#stop ⇒ Object
61 62 63 |
# File 'lib/nginx/server.rb', line 61 def stop `kill #{@nginx_pid}` end |