lib/rda/nginx.rb in rda-0.0.4 vs lib/rda/nginx.rb in rda-0.0.6
- old
+ new
@@ -17,12 +17,14 @@
set_passenger_user_and_group
include_sites_enabled
template("templates/nginx", "#{conf_path}/sites-available/#{hostname}")
link_file("#{conf_path}/sites-available/#{hostname}", "#{conf_path}/sites-enabled/#{hostname}")
-
- append_file "/etc/hosts", "127.0.0.1 #{hostname}"
+
+ unless configured?('/etc/hosts', "127.0.0.1 #{hostname}")
+ append_file "/etc/hosts", "127.0.0.1 #{hostname}"
+ end
end
desc "Discard", "Remove the Nginx setting of rails application"
def discard
return unless installed?
@@ -69,11 +71,11 @@
search_paths = DEFAULT_CONF_PATHS if search_paths.empty?
@paths ||= search_paths.select { |p| Dir.exists? p if p } unless search_paths.empty?
end
def prompt_not_found
- $stderr.puts "Config directory of Nginx is not found in the following paths:\n\n"
+ $stderr.puts "ERROR: Config directory of Nginx is not found in the following paths:\n\n"
Rda.config.nginx_conf_paths.each { |p| $stderr.puts "* #{p}" }
$stderr.puts "\n"
end
def ask_for_choosing_one
@@ -97,21 +99,46 @@
end
end
def set_passenger_user_and_group
conf = conf_path + '/nginx.conf'
- gsub_file conf, /http {/, <<-PASSENGER
+
+ unless configured?(conf, 'passenger_default_user')
+ gsub_file conf, /http {/, <<-PASSENGER
http {
passenger_default_user root;
+ PASSENGER
+ end
+
+ unless configured?(conf, 'passenger_default_group')
+ gsub_file conf, /http {/, <<-PASSENGER
+http {
passenger_default_group root;
- PASSENGER
+ PASSENGER
+ end
end
def include_sites_enabled
conf = conf_path + '/nginx.conf'
- gsub_file conf, /http {/, <<-INCLUDE_SITES_ENABLED
+ unless configured?(conf, "include #{conf_path}/sites-enabled/*;")
+ gsub_file conf, /http {/, <<-INCLUDE_SITES_ENABLED
http {
include #{conf_path}/sites-enabled/*;
- INCLUDE_SITES_ENABLED
+ INCLUDE_SITES_ENABLED
+ end
+ end
+
+ def configured?(fname, conf)
+ File.open(fname) do |f|
+ f.readlines.each do |l|
+ if l.strip.start_with?(conf)
+ $stderr.puts "INFO: #{conf} has already been set!"
+
+ return true
+ end
+ end
+ end
+
+ false
end
end
end