installer/unix-like/create_texts.rb in rhoconnect-3.1.2 vs installer/unix-like/create_texts.rb in rhoconnect-3.2.0.beta1
- old
+ new
@@ -30,21 +30,28 @@
options[:web_server] = "nginx"
opts.on('-w', '--web-server Server', ' Specify that you are using web server SERVER') do |server|
options[:web_server] = server
end #do
+ opts.on('-l', '--Logfile file', ' Specify installtion log file') do |file|
+ options[:log_file] = file
+ end #do
+
end #do
optparse.parse!
@prefix = options[:prefix]
@dist = options[:dist]
@redis = options[:redis]
@ruby_version = options[:rubyVersion]
@profile = (@dist == 'debian') ? '~/.profile' : '~/.bash_profile'
@server = options[:web_server]
+@log_file = options[:log_file]
+@passenger_root = Constants::PASSENGER_ROOT
+
def passenger_version
(`#{@prefix}/bin/passenger --version`.match /\d+\.\d+\.\d+/)[0]
end
# create_redis_init
@@ -227,11 +234,10 @@
File.open('/etc/logrotate.d/redis', 'w') { |f| f << redis_logrotate_conf }
end
#
# Nginx stuff ...
-
def create_nginx_init
nginx_init_script = <<'_NGINX_INIT_SCRIPT_'
#!/bin/sh
# Author: Ryan Norbauer http://norbauerinc.com
# Modified: Geoffrey Grosenbach http://topfunky.com
@@ -298,15 +304,15 @@
File.open(nginx_script, 'w') { |f| f << nginx_init_script }
# Make the init script executable
`chmod +x #{nginx_script}`
# Set run levels
-# if @dist == 'debian'
-# #`update-rc.d -f nginx defaults`
-# else
-# #`/sbin/chkconfig nginx on`
-# end
+ # if @dist == 'debian'
+ # #`update-rc.d -f nginx defaults`
+ # else
+ # #`/sbin/chkconfig nginx on`
+ # end
end
def create_nginx_logrotate
nginx_logrorate_conf = <<'_NGINX_LOGRORATE_CONF_'
@@ -327,11 +333,10 @@
end
def create_nginx_conf_files(app_name)
nginx_server_conf = <<'_NGINX_CONF_'
user nginx;
-
worker_processes 4;
error_log logs/error.log;
pid logs/nginx.pid;
@@ -365,32 +370,44 @@
FileUtils.mv("/opt/nginx/conf/nginx.conf", "/opt/nginx/conf/nginx.conf.bak") unless File.exist? "/opt/nginx/conf/nginx.conf.bak"
File.open('/opt/nginx/conf/nginx.conf', 'w' ) { |f| f << nginx_server_conf }
Dir.mkdir "/opt/nginx/conf/conf.d" unless File.exist? "/opt/nginx/conf/conf.d"
rho_vhost_conf = <<_VHOST_CONF_
+upstream thin_cluster {
+ server unix:/tmp/thin.sock;
+ #server unix:/tmp/thin.0.sock;
+ #server unix:/tmp/thin.1.sock;
+ #server unix:/tmp/thin.2.sock;
+ #server unix:/tmp/thin.3.sock;
+}
+
server {
listen 80;
root /opt/nginx/html/#{app_name}/public; # <-- be sure to point to 'public' folder of your application!
- passenger_enabled on;
-# access_log off; # <-- disable access logging
-# error_log /dev/null crit; # <-- disable error logging, but critical errors only
-}
+ # access_log off; # <-- disable access logging
+ # error_log /dev/null crit; # <-- disable error logging, but critical errors only
+
+ location / {
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Host $http_host;
+ proxy_redirect off;
+
+ proxy_pass http://thin_cluster;
+ }
+
+ error_page 500 502 503 504 /50x.html;
+ location = /50x.html {
+ root html;
+ }
+}
_VHOST_CONF_
- File.open('/opt/nginx/conf/conf.d/rhoconnect.conf', 'w' ) { |f| f << rho_vhost_conf }
- passenger_conf = <<_PASSENGER_CONF_
-passenger_root /opt/rhoconnect/lib/ruby/gems/1.8/gems/passenger-#{passenger_version};
-passenger_ruby /opt/rhoconnect/bin/ruby;
-passenger_max_pool_size 20;
-passenger_min_instances 6;
-_PASSENGER_CONF_
- File.open('/opt/nginx/conf/conf.d/passenger.conf', 'w' ) { |f| f << passenger_conf }
+ File.open('/opt/nginx/conf/conf.d/rhoconnect.conf', 'w' ) { |f| f << rho_vhost_conf }
end
-
# End of nginx stuff ...
-
# generate_common_info
# Generates the readme info that is common across all distributions
def generate_common_info
readme = <<_README_
@@ -454,91 +471,10 @@
readme = readme + readme_2
readme
end #generate_common_info
-def create_passenger_load
- if @dist == 'debian'
- passenger_load_file = '/etc/apache2/mods-available/passenger.load'
- else
- passenger_load_file = '/etc/httpd/conf.d/passenger.conf'
- end # if
-
- passenger_load = <<_PASSENGER_LOAD_
-LoadModule passenger_module /opt/rhoconnect/lib/ruby/gems/1.8/gems/passenger-#{passenger_version}/ext/apache2/mod_passenger.so
-PassengerRoot /opt/rhoconnect/lib/ruby/gems/1.8/gems/passenger-#{passenger_version}
-PassengerRuby /opt/rhoconnect/bin/ruby
-_PASSENGER_LOAD_
-
- File.open( passenger_load_file, 'w' ) { |f| f << passenger_load }
-end #create_passenger_load
-
-def create_apache_vhost
- if @dist == 'debian'
- vhost_file = '/etc/apache2/sites-available/rhoconnect'
- else
- vhost_file = '/etc/httpd/conf.d/rhoconnect.conf'
- end
- vhost = <<_VHOST_
-<VirtualHost *:80>
- ServerName www.yourhost.com
- DocumentRoot /var/www/rhoapp/public
- PassengerMaxPoolSize 20
- PassengerMinInstances 6
- #...
- <Directory /var/www/rhoconnect/public>
- AllowOverride all
- Options -MultiViews
- </Directory>
-</VirtualHost>
-_VHOST_
-
- File.open( vhost_file, 'w' ) { |f| f << vhost }
-end #create_apache_vhost
-
-# The debian Apache2 specific part of the readme and places it in options[:prefix]
-def debian_apache_readme
- readme = <<_README_
-4) Installer created the following Apache2 configuration files:
- - rhoconnect application template (/etc/apache2/sites-available/rhoconnect)
- - passenger module (/etc/apache2/mods-available/passenger.load)
-
- To complete setup of web server
- A) Configure virtual host for rhoconnect application:
- Edit the file /etc/apache2/sites-available/rhoconnect so that it reflects your specifications.
-
- B) Enable the virtual host:
- sudo a2ensite rhoconnect
-
- C) Load the passenger.load module
- sudo a2enmod passenger
-
- D) Start server to pick up the changes:
- sudo /etc/init.d/apache2 start
-_README_
-
- readme
-end
-
-# The non-debian Apache2 specific part of the readme file and places it in options[:prefix]
-def yum_apache_readme
- readme = <<_README_
-4) Installer created the following Apache2 configuration files:
- - rhoconnect application template (/etc/httpd/conf.d/rhoconnect.conf)
- - passenger module (/etc/httpd/conf.d/passenger.conf)
-
- To complete setup of web server
- A) Configure virtual host for rhoconnect application:
- Edit the file /etc/httpd/conf.d/rhoconnect.conf so that it reflects your specifications.
-
- B) As root user start server to pick up the changes:
- /sbin/service httpd start
-_README_
-
- readme
-end
-
def nginx_readme
readme = <<_NGINX_README_
4) Installer compiled Nginx web server (/opt/nginx) with the following configuration files:
- Nginx start-up script (/etc/init.d/nginx)
- Nginx logrotate settings (/etc/logrotate.d/nginx)
@@ -585,34 +521,54 @@
`#{rho_path}/bin/bundle install --without=test development`
Dir.chdir "../"
`chown -R nginx:nginx benchapp/`
end
+def config_and_install_thin_scripts(rho_path)
+ puts "Configuring and installing thin scripts ..."
+ `#{rho_path}/bin/thin install`
+
+ # >> Installing thin service at /etc/rc.d/thin ...
+ # mkdir -p /etc/rc.d
+ # writing /etc/rc.d/thin
+ # chmod +x /etc/rc.d/thin
+ # mkdir -p /etc/thin
+ #
+ # To configure thin to start at system boot:
+ # on RedHat like systems:
+ # sudo /sbin/chkconfig --level 345 thin on
+ # on Debian-like systems (Ubuntu):
+ # sudo /usr/sbin/update-rc.d -f thin defaults
+ # on Gentoo:
+ # sudo rc-update add thin default
+ #
+ # Then put your config files in /etc/thin
+
+ `#{rho_path}/bin/thin config -C /etc/thin/rhoapp.yml -c /opt/nginx/html/rhoapp/ --socket /tmp/thin.sock --log /opt/nginx/logs/thin.log --pid /var/run/thin.pid -e production`
+ `ln -s /etc/rc.d/thin /etc/init.d/.` if File.directory?('/etc/rc.d')
+end
+
def create_texts
if @redis
create_redis_init
create_redis_logrotate
end
if @server == 'nginx'
create_nginx_init
-
create_nginx_logrotate
+
@use_bench_app = File.exist? "#{@prefix}/installer/bench.tar.gz"
if @use_bench_app
create_nginx_conf_files "benchapp"
copy_benchapp @prefix
else
create_nginx_conf_files "rhoapp"
generate_rhoapp @prefix
end
-
+ config_and_install_thin_scripts(@prefix)
distro_info = nginx_readme
- else
- create_passenger_load
- create_apache_vhost
- distro_info = (@dist == 'debian') ? debian_apache_readme : yum_apache_readme
end
common_info = generate_common_info
readme = common_info + distro_info
File.open("#{@prefix}/README", 'w') { |f| f << readme }
@@ -639,32 +595,24 @@
B) To verify that application up and running open web console in your browser:
http://localhost/console/
_NGINX_TO_DO_
else
- if @server == 'nginx'
- server_todo_list = <<_NGINX_TO_DO_
+ server_todo_list = <<_NGINX_TO_DO_
2) Try rhoconnect 'rhoapp' application, created in /opt/nginx/html directory
A) As root user start redis and nginx servers:
/etc/init.d/redis start
/etc/init.d/nginx start
+ /etc/init.d/thin start
B) Open RhoConnect application web console in your browser:
http://localhost/console/
_NGINX_TO_DO_
- else
- server_todo_list = <<_APACHE2_TO_DO_
-2) Complete setup of Apache2 web server
- A) Configure virtual host for your rhoconnect application:
- Edit the file /etc/httpd/conf.d/rhoconnect.conf so that it reflects your specifications.
- B) As root user start server to pick up the changes:
- /sbin/service httpd start
-
-_APACHE2_TO_DO_
- end
end
- puts afterwords + about_app + "For more details see #{@prefix}/README file."
-
-end #create_texts
+ afterwords << about_app
+ afterwords << "For more details see #{@prefix}/README file."
+ puts afterwords
+ File.open("#{@log_file}", 'a') { |f| f << afterwords } if @log_file
+end
create_texts