Class: Passify::CLI
- Inherits:
-
Thor
- Object
- Thor
- Passify::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/passify/cli.rb
Constant Summary collapse
- APACHE_CONF =
'/etc/apache2/httpd.conf'
- VHOSTS_DIR =
'/private/etc/apache2/passenger_pane_vhosts'
Instance Method Summary collapse
- #add(name = nil) ⇒ Object
- #conf ⇒ Object
- #environment(env = nil) ⇒ Object
- #install ⇒ Object
- #list ⇒ Object
- #open ⇒ Object
- #remove(name = nil) ⇒ Object
- #restart ⇒ Object
- #uninstall ⇒ Object
- #version ⇒ Object
Instance Method Details
#add(name = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/passify/cli.rb', line 20 def add(name = nil) check_for_passify error("This directory can not be served with passify. It has to be either a Rack application, a Rails 2.x application or a legacy (PHP/HTML) application.") unless is_valid_app? host = get_host_from_name(name) if app_exists?(host) if is_same_app?(host, pwd) notice("This directory is already being served from http://#{host}. Run `passify open` to view it.") else exit if no?("A different app already exists under http://#{host}. Do you want to overwrite it?") sudome remove_app(host) end end silent_create_file ".passify", host sudome create_vhost(host, pwd) register_host(host) restart_apache say "The application was successfully set up and can be reached from http://#{host} . Run `passify open` to view it." end |
#conf ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/passify/cli.rb', line 130 def conf check_for_passify host = find_host success = false if ENV['EDITOR'] Dir.chdir(VHOSTS_DIR) do success = system("#{ENV['EDITOR']} #{vhost_file(host)}") end end if !success say vhost_file(host) end end |
#environment(env = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/passify/cli.rb', line 53 def environment(env = nil) check_for_passify notice("This application is a legacy application. The environment can not be changed.") if !is_rack_app? && !is_rails2_app? host = find_host line_no, rack_env = `grep -n 'RackEnv' #{vhost_file(host)}`.split(":") current_env = rack_env.strip.split(" ")[1] if env.nil? || env.empty? say "The application is running in '#{current_env}' environment." else notice("The application is already in '#{env}' environment.") if current_env == env sudome `sed -i '' '#{line_no}s!#{current_env}!#{env}!' #{vhost_file(host)}` restart_apache say "The application now runs in '#{env}' environment." end end |
#install ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/passify/cli.rb', line 72 def install error("Passenger seems not to be installed. Refer to http://www.modrails.com/ for installation instructions.") unless passenger_installed? notice("passify is already installed.") if passify_installed? sudome append_to_file APACHE_CONF, <<-eos \n\n# Added by the Passenger preference pane # Make sure to include the Passenger configuration (the LoadModule, # PassengerRoot, and PassengerRuby directives) before this section. <IfModule passenger_module> NameVirtualHost *:80 <VirtualHost *:80> ServerName _default_ </VirtualHost> Include /private/etc/apache2/passenger_pane_vhosts/*.conf </IfModule> eos restart_apache FileUtils.mkdir_p(VHOSTS_DIR) say "The installation of passify is complete." end |
#list ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/passify/cli.rb', line 110 def list check_for_passify Dir.foreach(VHOSTS_DIR) do |entry| if File.file?("#{VHOSTS_DIR}/#{entry}") host = entry[0..-12] dir = directory_for_host(host) say " #{host} --> #{Dir.exists?(dir) ? dir : "[REMOVED]"}" end end end |
#open ⇒ Object
122 123 124 125 126 127 |
# File 'lib/passify/cli.rb', line 122 def open check_for_passify host = find_host system("open http://#{host}") end |
#remove(name = nil) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/passify/cli.rb', line 43 def remove(name = nil) check_for_passify host = find_host(name) sudome remove_app(host) say "The application was successfully removed." end |
#restart ⇒ Object
103 104 105 106 107 |
# File 'lib/passify/cli.rb', line 103 def restart notice("The current directory does not seem to be a passenger application.") unless is_valid_app? FileUtils.mkdir_p('tmp') system "touch tmp/restart.txt" end |
#uninstall ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/passify/cli.rb', line 94 def uninstall notice("passify is not installed.") unless passify_installed? sudome first_config_line = find_line_in_conf('# Added by the Passenger preference pane').to_i system("sed -i '' '#{first_config_line},#{first_config_line+9}d' #{APACHE_CONF}") say "The uninstallation of passify is complete. The vhosts in `#{VHOSTS_DIR}` have not been deleted." end |