Permalink
Browse files

Cleaning launching, shutdown, docs.

- Make the stop script more configurable, and give lighttpd a chance to cleanup first
- Only launch a single php-cgi helper process
- Add docs on installing wordpress demo
  • Loading branch information...
1 parent d8a8cdb commit 803a14d84fff803c55ac396ffeff21bc989d7607 @paulj committed Apr 17, 2011
Showing with 95 additions and 7 deletions.
  1. +9 −3 cloud_controller/staging/common.rb
  2. +19 −4 cloud_controller/staging/php/plugin.rb
  3. +67 −0 docs/php.md
@@ -384,16 +384,22 @@ def generate_startup_script(env_vars = {})
<%= start_command %> > ../logs/stdout.log 2> ../logs/stderr.log &
STARTED=$!
echo "$STARTED" >> ../run.pid
-echo "#!/bin/bash" >> ../stop
-echo "kill -9 $STARTED" >> ../stop
-echo "kill -9 $PPID" >> ../stop
+<%= stop_script_template.lines.map { |l| "echo " + l.strip.inspect + " >> ../stop\n" }.join %>
chmod 755 ../stop
wait $STARTED
SCRIPT
# TODO - ERB is pretty irritating when it comes to blank lines, such as when 'after_env_before_script' is nil.
# There is probably a better way that doesn't involve making the above Heredoc horrible.
ERB.new(template).result(binding).lines.reject {|l| l =~ /^\s*$/}.join
end
+
+ def stop_script_template
+ <<-SCRIPT
+ #!/bin/bash
+ kill -9 $STARTED
+ kill -9 $PPID
+ SCRIPT
+ end
# Generates newline-separated exports for the specified environment variables.
# If the value of one of the keys is false or nil, it will be an 'unset' instead of an 'export'
@@ -6,7 +6,6 @@ def framework
end
def stage_application
- # TODO: Stop script uses kill -9, and this means we're not cleaning up php-cgi workers.
Dir.chdir(destination_directory) do
create_app_directories
copy_source_files
@@ -20,14 +19,30 @@ def start_command
"lighttpd -f ../lighttpd.config -D"
end
+ # Nicer kill script that attempts an INT first, and then only if the process doesn't die will
+ # we try a -9.
+ def stop_script_template
+ <<-SCRIPT
+ #!/bin/bash
+ MAX_NICE_KILL_ATTEMPTS=20
+ attempts=0
+ kill -INT $STARTED
+ while pgrep $STARTED >/dev/null; do
+ (( ++attempts >= MAX_NICE_KILL_ATTEMPTS )) && break
+ sleep 1
+ done
+ pgrep $STARTED && kill -9 $STARTED
+ kill -9 $PPID
+ SCRIPT
+ end
+
private
def startup_script
vars = environment_hash
generate_startup_script(vars)
end
def create_lighttpd_config
- # TODO: Handle multiple instances that would share the same socket
File.open('lighttpd.config', 'w') do |f|
f.write <<-EOT
server.document-root = var.CWD
@@ -51,10 +66,10 @@ def create_lighttpd_config
((
"bin-path" => "/usr/bin/php-cgi",
"socket" => env.HOME + "/php.socket",
- "max-procs" => 2,
+ "max-procs" => 1,
"idle-timeout" => 20,
"bin-environment" => (
- "PHP_FCGI_CHILDREN" => "4",
+ "PHP_FCGI_CHILDREN" => "0",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
View
@@ -0,0 +1,67 @@
+# PHP Support
+
+## Architecture
+
+PHP applications are deployed using a combination of lighttpd and php-cgi. For each CloudFoundry instance of the application,
+a pair of lighttpd and php-cgi instances are created.
+
+## Demo: Installing Wordpress ##
+The Wordpress CMS can be run using CloudFoundry PHP support with very minimal changes.
+
+Steps to get the application to run:
+
+1. <code>mkdir wordpresscf; cd wordpresscf</code>
+2. <code>wget http://wordpress.org/latest.tar.gz</code>
+3. <code>tar -xzf latest.tar.gz</code>
+4. <code>rm latest.tar.gz</code>
+5. <code>mv wordpress/* .</code>
+6. <code>rm -r wordpress</code>
+7. Create wp-config.php, and set it to (note that changing the keys would be a *really* good idea):
+
+ <?php
+ $services = getenv("VCAP_SERVICES");
+ $services_json = json_decode($services,true);
+ $mysql_config = $services_json["mysql-5.1"][0]["credentials"];
+
+ // ** MySQL settings from resource descriptor ** //
+ define('DB_NAME', $mysql_config["name"]);
+ define('DB_USER', $mysql_config["user"]);
+ define('DB_PASSWORD', $mysql_config["password"]);
+ define('DB_HOST', $mysql_config["hostname"]);
+ define('DB_PORT', $mysql_config["port"]);
+
+ define('DB_CHARSET', 'utf8');
+ define('DB_COLLATE', '');
+
+ /**#@+
+ * Authentication Unique Keys and Salts.
+ *
+ * Change these to different unique phrases!
+ * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
+ * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
+ *
+ * @since 2.6.0
+ */
+ define('AUTH_KEY', 'B-A+*zyVM$L}w&V-w.,5.=Lj|<)LY(oaYNh7kRZC:Lv3KxGse:/nIZ.VV/_|bw<&');
+ define('SECURE_AUTH_KEY', 'e<j )h1FBdyQCm=rg01e&L+tSx>J_`&J:Wjr!t7:Gm{^]lWYfm&,zwN9/3l(Q;Ba');
+ define('LOGGED_IN_KEY', '{{|Sj:P;3A6m><er05a44KGom-bheE8u-!3C0<[-=bHhb6p@8ic~,a!<GS]rNKi&');
+ define('NONCE_KEY', 'x>.$Qn)6<3Yfl9Bo8`KOD+; 2J<|kx{?I^kMunvN:dh|%=BRzsuJC!F<m|5BN!<g');
+ define('AUTH_SALT', '-+u: SaC9C7+[3Wb?$+s89h)A<PZ8w6l9[?q|X*gHiG{m#6,Fs;sI&|MQm&6&[?q');
+ define('SECURE_AUTH_SALT', '%j/fc+a@f1Ftw%$Jy*~O)}}2j<!.7gh>N.hKF3c2-r(,--I3}t,[l7@:;p=U$Hxb');
+ define('LOGGED_IN_SALT', 'tElqJ6L*|wbZ@g&|,+}q;fO|7,I$K,?E7~-|7;%3#KoynCl-t`J]T84M2h5wx [:');
+ define('NONCE_SALT', 'mv3qj@@- mzDj457< T+CwW`_UtANx`eaA@rkgW]GBOe],g/OE HTscD{|abEy[2');
+ $table_prefix = 'wp_';
+ define ('WPLANG', '');
+ define('WP_DEBUG', false);
+
+ /* That's all, stop editing! Happy blogging. */
+
+ /** Absolute path to the WordPress directory. */
+ if ( !defined('ABSPATH') )
+ define('ABSPATH', dirname(__FILE__) . '/');
+
+ /** Sets up WordPress vars and included files. */
+ require_once(ABSPATH . 'wp-settings.php');
+8. <code>vmc push wordpresscf --url wordpresscf.vcap.me -n</code>
+9. <code>vmc create-service mysql --bind wordpresscf</code>
+10. Visit http://wordpresscf.vcap.me and enjoy your Wordpress install!

0 comments on commit 803a14d

Please sign in to comment.