class Nginxtra::Actions::Compile
The Nginxtra::Actions::Compile
class encapsulates compiling nginx so it is ready with the specified compile options. An optional option of :force can be passed with true to make compilation happen no matter what.
Public Instance Methods
Run the full compilation of nginx.
# File lib/nginxtra/actions/compile.rb, line 11 def compile return up_to_date unless should_compile? copy_to_base configure make make "install" update_last_compile end
Configure nginx with the specified compile options.
# File lib/nginxtra/actions/compile.rb, line 26 def configure @thor.inside Nginxtra::Config.src_dir do run! "sh configure --prefix=#{Nginxtra::Config.build_dir} --conf-path=#{Nginxtra::Config.nginx_config} --pid-path=#{Nginxtra::Config.nginx_pidfile} #{@config.compile_options}" end end
Copy the nginx source directory to the base directory.
# File lib/nginxtra/actions/compile.rb, line 21 def copy_to_base @thor.directory "vendor/nginx", Nginxtra::Config.src_dir end
Determine if the compile options differ from those last compiled with.
# File lib/nginxtra/actions/compile.rb, line 50 def different_compile_options? Nginxtra::Status[:last_compile_options] != @config.compile_options end
Determine if the last nginx compiled version is different from the current nginx version.
# File lib/nginxtra/actions/compile.rb, line 56 def different_nginx_version? Nginxtra::Status[:last_compile_version] != Nginxtra::Config.nginx_version end
Run make against the configured nginx.
# File lib/nginxtra/actions/compile.rb, line 33 def make(*args) @thor.inside Nginxtra::Config.src_dir do run! ["make", *args].join(" ") end end
Determine if compiling should happen. This will return false if the last compile options equal the current options and the last compile version is the same as the current nginx version, or if the force option was passed in at construction time.
# File lib/nginxtra/actions/compile.rb, line 43 def should_compile? return true if force? different_compile_options? || different_nginx_version? end
Notify the user that the compilation is up to date
# File lib/nginxtra/actions/compile.rb, line 69 def up_to_date @thor.say "nginx compilation is up to date" end
Update Nginxtra::Status
with the last compile time and options.
# File lib/nginxtra/actions/compile.rb, line 62 def update_last_compile Nginxtra::Status[:last_compile_options] = @config.compile_options Nginxtra::Status[:last_compile_time] = Time.now Nginxtra::Status[:last_compile_version] = Nginxtra::Config.nginx_version end