peppyheppy-cpanel-passenger 0.0.2 → 0.0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,17 +4,27 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- This gem consists of a single script that enables a cpanel account to run a Ruby on Rails App. Many more improvements could/should be made to handle more cases.
7
+ This gem consists of a single script that enables a cpanel account to run a Ruby on Rails App. Many more improvements could/should be made to handle more cases.
8
+
9
+ Originally I was going to do a lot more with this, but then decided that I didn't need to for my needs.
8
10
 
9
11
  == FEATURES/PROBLEMS:
10
12
 
11
13
  * It currently configures a Passenger enabled Apache web server for the provided rails app
12
- * It doesn't do anything else at the moment.
14
+ * It doesn't do anything else at the moment
13
15
 
14
16
  == SYNOPSIS:
15
17
 
18
+ - Generate/Setup Config (simple)
16
19
  cpanel-passenger --username=peppyheppy --path=/home/peppyheppy/rails_app
17
20
 
21
+ - View previously generated config
22
+ cpanel_passenger --username=peppyheppy --path=/home/peppyheppy/rails_app --show-current-config
23
+
24
+ - Add Additional Custom Passenger Configurations
25
+ cpanel-passenger --username=peppyheppy --path=/home/peppyheppy/rails_app --misc-config="PassengerMaxRequests 100,PassengerStatThrottleRate 2"
26
+ (see http://www.modrails.com/documentation/Users guide.html for more parameters)
27
+
18
28
  == REQUIREMENTS:
19
29
 
20
30
  Must be run as root since it will modify the Apache httpd.conf files.
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module CpanelPassenger
5
- VERSION = '0.0.2'
5
+ VERSION = '0.0.3.1'
6
6
  end
@@ -1,13 +1,19 @@
1
1
  require 'optparse'
2
2
  require 'ftools'
3
+ require 'fileutils'
3
4
 
4
5
  module CpanelPassenger
5
6
  class CLI
7
+
6
8
  def self.execute(stdout, arguments=[])
7
9
 
8
10
  options = {
9
11
  :username => nil,
10
- :path => nil
12
+ :path => nil,
13
+ :maxpoolsize => nil,
14
+ :poolidletime => nil,
15
+ :showcurrentconfig => nil,
16
+ :miscconfig => nil
11
17
  }
12
18
  mandatory_options = %w( username path )
13
19
 
@@ -20,11 +26,24 @@ module CpanelPassenger
20
26
  Options are:
21
27
  BANNER
22
28
  opts.separator ""
29
+ opts.on("-c", "--show-current-config",
30
+ "Show the current config for an account; requires -u and -p") { |arg| options[:showcurrentconfig] = true }
23
31
  opts.on("-p", "--path=PATH", String,
24
- "The absolute path to your rails application root (ex: /home/username/blog)",
25
- "Default: ~") { |arg| options[:path] = arg }
32
+ "The absolute path to your rails application root (ex: /home/username/blog/current)") { |arg| options[:path] = arg }
26
33
  opts.on("-u", "--username=USERNAME", String,
27
- "Your cpanel account username (ex: peppyheppy)") { |arg| options[:username] = arg.strip }
34
+ "Your cpanel account username (ex: peppyhep)") { |arg| options[:username] = arg.strip }
35
+ opts.on("-d", "--domain=domain", String,
36
+ "The domain for this username (ex: peppyheppy.com)") { |arg| options[:domain] = arg.strip }
37
+ opts.on("-s", "--max-pool-size=SIZE", String,
38
+ "Value for PassengerMaxPoolSize which is used for setting",
39
+ "the max number of application instances") { |arg| options[:maxpoolsize] = arg.strip }
40
+ opts.on("-t", "--pool-idle-time=TIME", String,
41
+ "Value for PassengerPoolIdleTime which sets the idle time",
42
+ "for an application instance before it shuts down") { |arg| options[:poolidletime] = arg.strip }
43
+ opts.on("-m", "--misc-config='OPV V,OPT V'", String,
44
+ "List of comma-delimited Passenger configuration parameters with values;",
45
+ "don't forget to to wrap multiple arguments in quotes.",
46
+ "(PassengerParam1 1,PassengerParam2 99)") { |arg| options[:miscconfig] = arg.split(',').map { |config| "#{config.strip}\n" } unless arg.nil? }
28
47
  opts.on("-h", "--help",
29
48
  "Show this help message.") { stdout.puts opts; exit }
30
49
  opts.parse!(arguments)
@@ -36,24 +55,54 @@ module CpanelPassenger
36
55
 
37
56
  username = options[:username]
38
57
  rails_app_path = options[:path]
58
+ apache_config_root = '/usr/local/apache/conf'
59
+ apache_userdata_config_root = "#{apache_config_root}/userdata/std/2"
39
60
 
40
61
  stdout.puts "* Setting up Rails app in Apache config for user"
41
62
  raise "Path is required!" unless File.directory?(rails_app_path) or File.directory?("#{rails_app_path}/public")
42
63
  raise "Script needed for overriding or appending vhost includes is not found, do you have cpanel installed?" unless File.exists?("/scripts/ensure_vhost_includes")
43
-
44
- stdout.puts "* Fetching info from httpd.conf"
45
- path_to_config = File.new("/usr/local/apache/conf/httpd.conf").readlines.grep(/userdata\/.*\/#{username}/).first.strip[/\/usr\/.*[*]/].chop + "rails.conf"
64
+
65
+ unless File.directory?("#{apache_userdata_config_root}/#{username}")
66
+ raise "Apache is not yet configured for your virtual host configurations... please provide the domain (-d/--domain)" unless options[:domain]
67
+ stdout.puts "* Making required apache config dirs."
68
+ config_path = "#{apache_userdata_config_root}/#{username}/#{options[:domain]}"
69
+ FileUtils::mkdir_p(config_path)
70
+ path_to_config = config_path + "/rails.conf"
71
+ end
46
72
 
47
- stdout.puts "* Creating configs for #{username}"
48
- file = File.open(path_to_config, "w+")
49
- file.write "# line added by cpanel passenger script\n"
50
- file.write "DocumentRoot #{rails_app_path}/public"
51
- file.close
73
+ stdout.puts "* Fetching info from httpd.conf"
74
+ path_to_config ||= File.new("/usr/local/apache/conf/httpd.conf").readlines.grep(/userdata\/.*\/#{username}/).first.strip[/\/usr\/.*[*]/].chop + "rails.conf"
52
75
 
53
- stdout.puts "* Enabling the configs for #{username}"
54
- `/scripts/ensure_vhost_includes --user=#{username}`
76
+ unless options[:showcurrentconfig]
77
+ stdout.puts "* Creating configs for #{username}"
78
+ file = File.open(path_to_config, "w+")
79
+ file.write "# line added by cpanel passenger script\n"
80
+ file.write "DocumentRoot #{rails_app_path}/public\n"
81
+ # optionsal parameters
82
+ unless options[:maxpoolsize].nil?
83
+ file.write "PassengerMaxPoolSize #{options[:maxpoolsize]}\n" if options[:maxpoolsize].to_i > 0
84
+ end
85
+ unless options[:poolidletime].nil?
86
+ file.write "PassengerPoolIdleTime #{options[:poolidletime]}\n" if options[:poolidletime].to_i > 0
87
+ end
88
+ # misc parameters
89
+ unless options[:miscconfig].nil? or options[:miscconfig].size == 0
90
+ options[:miscconfig].each { |config| file.write("#{config}\n") }
91
+ end
92
+ file.close
93
+ stdout.puts "* Enabling the configs for #{username}"
94
+ `/scripts/ensure_vhost_includes --user=#{username}`
55
95
 
56
- stdout.puts "* Done. You can view the config changes in #{path_to_config}"
96
+ stdout.puts "* Done. You can view the config changes in #{path_to_config}"
97
+ else
98
+ if File.exists?(path_to_config)
99
+ puts "---- CONFIG ----"
100
+ File.new(path_to_config).each { |line| puts line }
101
+ puts "---- EOF CONFIG ----"
102
+ else
103
+ puts "Passenger is not configured for this username."
104
+ end
105
+ end
57
106
  end
58
107
  end
59
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peppyheppy-cpanel-passenger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Hepworth