$:.unshift File.expand_path(File.dirname(__FILE__)) require 'optparse' options = {} optparse = OptionParser.new do |opts| options[:dist] = nil opts.on( '-d', '--dist DISTRO', 'Specify DISTRO as the current distribution.' ) do |dist| options[:dist] = dist end #do options[:prefix] = '/opt/rhoconnect/' opts.on( '-p', '--prefix RHODIR', 'Specify RHODIR as the prefix directory.' ) do |dir| options[:prefix] = dir end #do options[:redis] = true opts.on( '--no-redis', '', 'Skip installing the redis server.' ) do options[:redis] = false end #do options[:rubyVersion] = 'rubyee' opts.on( '-r', '--rubyVer VERSION', 'Specify VERSION as the verion of ruby that is installed.' ) do |rubyVer| options[:rubyVersion] = rubyVer 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' # create_redis_init # Creates the redis initialization file and places it into the correct directory def create_redis_init redisInit="/etc/init.d/redis" redis_init_script = <<'_REDIS_INIT_SCRIPT_' #!/usr/bin/env bash ### BEGIN INIT INFO # Provides: redis-server # Required-Start: $syslog # Required-Stop: $syslog # Should-Start: $local_fs # Should-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: redis-server - Persistent key-value db # Description: redis-server - Persistent key-value db ### END INIT INFO # # Author: Wayne E. Seguin # License: The same licence as Redis, New BSD # http://www.opensource.org/licenses/bsd-license.php # # Source the system config file, if it exists. if [[ -s /etc/conf.d/redis ]] ; then source /etc/conf.d/redis fi # Default config variables that have not been set. port="${port:-6379}" prefix="${prefix:-/opt/rhoconnect}" redis="${prefix}bin/redis-server" redis_cli="${prefix}bin/redis-cli" pidfile="${pidfile:-/var/run/redis.pid}" config="${config:-/opt/rhoconnect/etc/redis.conf}" user="${user:-root}" #prefix="${prefix:-/usr/local}" #config="${config:-/usr/local/etc/redis.conf}" #pidfile="${pidfile:-/var/run/redis/redis.pid}" #config="${config:-/etc/redis/redis.conf}" #user="${user:-redis}" # # Set the running $pid value based on $pidfile. # if [[ -s "$pidfile" ]] ; then pid=$(cat $pidfile) else rm -f $pidfile fi # In case there was pidfile corruption... if [[ "Linux" = "$(uname)" ]] ; then # /proc does not exist on say, Darwin if [[ ! -z "${pid}" ]] && [[ ! -x "/proc/${pid}" ]] ;then pid="$(ps auxww | grep [r]edis | grep "$config" | grep -v 'grep' | awk '{print $2}')" elif [[ -z "${pid}" ]] ; then pid="$(ps auxww | grep [r]edis | grep "$config" | grep -v 'grep' | awk '{print $2}')" fi else if [[ -z "${pid}" ]] ; then pid="$(ps auxww | grep [r]edis | grep "$config" | grep -v 'grep' | awk '{print $2}')" fi fi # # Start redis using redis-server as user 'redis'. # redis_start() { if [[ -f $pidfile ]] ; then echo "$pidfile exists, redis-server is either already running or crashed." exit 1 elif [[ ! -z "$pid" ]] ; then echo -e "\nRedis is already running with configuration '$config'." echo "$pid" > $pidfile # Ensure pidfile exists with the pid. else echo "Starting Redis server..." su $user -c "$redis $config" exit 0 fi } # # Stop redis using redis-cli SHUTDOWN. # redis_stop() { echo -n "Stopping redis server on port ${port} ... " "$redis_cli" -p ${port} SHUTDOWN # Keep user informed while server shuts down. echo "Waiting for the redis server to shutdown " if [[ "Linux" = "$(uname)" ]] ; then if [[ "${pid}" = "" ]] ; then echo "redis server is not running." # Clear out the old pidfile if available rm -f $pidfile exit 1 fi while [[ -x /proc/${pid} ]] ; do echo -n '.' ; sleep 1 done else # Darwin, etc... while [[ ! -z "$(ps auxww | grep [r]edis | grep "$config" | awk '{print $2}')" ]] ; do echo -n '.' ; sleep 1 done fi # Clear out the old pidfile. rm -f $pidfile # Notify user of successful completion. echo -e "redis server stopped." exit 0 } redis_usage() { echo -e "Usage: $0 {start,stop}" exit 1 } # # CLI logic. # case "$1" in start) redis_start ;; stop) redis_stop ;; *) redis_usage ;; esac _REDIS_INIT_SCRIPT_ File.open(redisInit, 'w') { |f| f << redis_init_script } # Make the init script executable `chmod +x #{redisInit}` # Set run levels if @dist == 'debian' `update-rc.d -f redis defaults` else `/sbin/chkconfig redis on` # `/sbin/chkconfig --list redis` end redis_init_script end #create_redis_init def create_redis_logrotate redis_logrotate_conf = <<'_REDIS_LOGRORATE_CONF_' /var/log/redis.log { rotate 3 missingok notifempty size 250k create 0644 root root compress } _REDIS_LOGRORATE_CONF_ File.open('/etc/logrotate.d/redis', 'w') { |f| f << redis_logrotate_conf } end # generate_common_info # Generates the readme info that is common across all distributions def generate_common_info readme = <<_README_ Thank you for choosing Rhomobile for your cross-platform app needs! To finish this setup, please complete the following... 1) Add necessary bins to the path(s) of the users who will be using this software. You may also wish to add these items to your #{@profile} to automatically add them upon login. Ex: A) All bins in the main bin deposit: export PATH=#{@prefix}bin:$PATH B) Bins specifically placed in the ruby/bin directory export PATH=#{@prefix}ruby/1.8/bin:$PATH Or if you had other versions of ruby installed previously to running this installation, you may instead wish to simply create an alias for the newly installed ruby. Ex: alias #{@ruby_version}=#{@prefix}bin/ruby B) Add the export line to #{@profile}: export PATH=#{@prefix}bin:#{@prefix}ruby/bin:$PATH C) Add #{@prefix}lib to your library path like so: export LD_LIBRARY_PATH=#{@prefix}lib:$LD_LIBRARY_PATH Note: You may also want to add this line to #{@profile} 2) Rhoconnect installer configured redis server with the following settings: A) redis.conf file is located in #{@prefix}etc/ directory with properties: daemonize yes pidfile /var/run/redis.pid logfile /var/log/redis.log B) Redis logrotate settings for /var/log/redis.log files defined in '/etc/logrotate.d/redis': /var/log/redis.log { rotate 3 missingok notifempty size 250k create 0644 root root compress } C) Redis start-up script '/etc/init.d/redis'. You can start/stop redis server by running the following commands: /etc/init.d/redis {start|stop} 3) Setup rhoconnect application directory     A) Put your application code in a directory called /var/www/rhoconnect (make sure this is the root of your applictaion directory, i.e. /var/www/rhoconnect/config.ru should exist). B) Make an empty public folder in the directory $ mkdir /var/www/rhoconnect/public _README_ 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-3.0.8/ext/apache2/mod_passenger.so PassengerRoot /opt/rhoconnect/lib/ruby/gems/1.8/gems/passenger-3.0.8 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_ ServerName your.server.name.goes.here.com DocumentRoot /var/www/rhoconnect/public PassengerMaxPoolSize 20 PassengerMinInstances 6 #... _VHOST_ File.open( vhost_file, 'w' ) { |f| f << vhost } end #create_apache_vhost # create_debian_readme # Creates the debian specific part of the readme and places it in options[:prefix] def create_debian_readme readme = <<_README_ 4) Configure Apache2 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.load D) Restart apache to pick up the changes: $ sudo /etc/init.d/apache2 restart _README_ readme end #create_debian_readme # create_yum_readme # Creates the non-debian specific part of the readme file and places it in options[:prefix] def create_yum_readme readme = <<_README_ 4) Configure Apache2 A) Configure virtual host for rhoconnect application: Edit the file /etc/httpd/conf.d/rhoconnect.conf so that it reflects your specifications. B) Restart apache to pick up the changes: $ sudo /sbin/service httpd restart _README_ readme end #create_yum_readme def create_texts if @redis create_redis_init create_redis_logrotate end create_passenger_load create_apache_vhost puts generate_common_info distro_info = (@dist == 'debian') ? create_debian_readme : create_yum_readme puts distro_info File.open("#{@prefix}README", 'w') do |f| f << generate_common_info f << distro_info end end #create_texts create_texts