Skip to content
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 05, 2011
@jonjensen jonjensen Improve camp_subdirectories handling to allow deeper paths dc66697
@jonjensen jonjensen Add better support for db_host option for PostgreSQL
This is especially helpful on Debian.
0181206
@jonjensen jonjensen Incompatible change: No longer interpolate httpd/conf/httpd.conf by d…
…efault

After applying this update, you must add httpd/conf/httpd.conf to
camp-config-files or your camp Apache configuration will no longer be
interpolated and copied into place.

This is necessary to enable camps to work right with nginx, and no longer
assume Apache is used at all.
e55231a
@jonjensen jonjensen Add support for other application servers with app_* settings 5b41c0d
@jonjensen jonjensen Support non-Apache webservers with skip_apache and httpd_{start,stop,…
…restart} settings
38439c1
Showing with 111 additions and 34 deletions.
  1. +3 −0 bin/mkcamp
  2. +3 −2 bin/psql_camp
  3. +3 −0 bin/refresh-camp
  4. +102 −32 lib/Camp/Master.pm
View
3 bin/mkcamp
@@ -108,6 +108,9 @@ vcs_checkout($opt{replace}) unless $opt{skipvcs};
# Must prepare database before installing templates; do so now.
prepare_database($opt{replace}) unless $opt{skipdb};
+# Create needed empty directories
+create_camp_subdirectories();
+
# Perform simple copy/symlink operations
process_copy_paths();
View
5 bin/psql_camp
@@ -29,12 +29,13 @@ initialize(
);
my $conf = config_hash();
+my $host = $conf->{db_host};
my $port = $conf->{db_port};
$ENV{PGUSER} ||= $conf->{db_default_user};
$ENV{PGDATABASE} ||= $conf->{db_default_database};
-exec '/usr/bin/psql', '-p', $port, @ARGV;
+exec '/usr/bin/psql', '-h', $host, '-p', $port, @ARGV;
=pod
@@ -45,7 +46,7 @@ psql_camp - invoke the psql client for a camp PostgreSQL instance
=head1 VERSION
-3.00
+3.01
=head1 SYNOPSIS
View
3 bin/refresh-camp
@@ -65,8 +65,11 @@ if (!$showpod) {
}
if ($opt{files}) {
+ create_camp_subdirectories();
+
# process_copy_paths() uses rsync for file copying, so it functions like an update
process_copy_paths();
+
$operation++;
}
View
134 lib/Camp/Master.pm
@@ -16,7 +16,7 @@ use DBI;
use Exporter;
use base qw(Exporter);
-our $VERSION = '3.01';
+our $VERSION = '3.02';
@Camp::Master::EXPORT = qw(
base_path
@@ -32,6 +32,7 @@ our $VERSION = '3.01';
camp_user_tmpdir
config_hash
create_camp_path
+ create_camp_subdirectories
dbh
db_path
default_camp_type
@@ -40,6 +41,7 @@ our $VERSION = '3.01';
get_next_camp_number
has_ic
has_rails
+ has_app
initialize
install_templates
mysql_path
@@ -78,7 +80,7 @@ Camp::Master - library routines for management of camps
=head1 VERSION
-3.01
+3.02
=cut
@@ -87,6 +89,7 @@ my (
@base_edits,
@edits,
%edits,
+ $has_app,
$has_rails,
$has_ic,
$initialized,
@@ -104,7 +107,6 @@ my (
);
@base_edits = qw(
- httpd/conf/httpd.conf
);
$base_camp_user = 'camp';
@@ -300,6 +302,19 @@ sub type_path {
return File::Spec->catfile( base_path(), $local_type, );
}
+sub create_camp_subdirectories {
+ my $conf = config_hash();
+
+ my $dirs = $conf->{camp_subdirectories};
+ ref($dirs) eq 'ARRAY' and @$dirs or return 1;
+
+ -d $conf->{path} or die "Error in camp_subdirectories: main camp path '$conf->{path}' doesn't exist\n";
+
+ my $cwd = pushd($conf->{path}) or die "Couldn't chdir $conf->{path}: $!\n";
+
+ return File::Path::mkpath(@$dirs, { verbose => 1 });
+}
+
sub copy_paths_config_path {
return File::Spec->catfile( type_path(), 'copy-paths.yml' );
}
@@ -572,6 +587,13 @@ sub db_config_path_mysql {
die "Cannot locate mysql/my.cnf in type definition or base camp user!\n";
}
+sub has_app {
+ die "Cannot call has_app() until package has been initialized!\n" unless $initialized;
+ my $conf = config_hash();
+ return $has_app if defined $has_app;
+ return $has_app = (grep /\S/, map { $conf->{"app_$_"} } qw( start stop )) ? 1 : 0;
+}
+
sub has_rails {
die "Cannot call has_rails() until package has been initialized!\n" unless $initialized;
return $has_rails if defined $has_rails;
@@ -926,6 +948,26 @@ Specify location of configuration file under "httpd_path" and include that in co
For example, "conf/apache2.conf", used when executable has been compiled with a specific full path. To detect need for this option see httpd -V output and check for "SERVER_CONFIG_FILE" with a value similar to "/etc/apache2/apache2.conf" (any path beginning with "/").
+=item skip_apache
+
+A boolean (0/1) setting that determines whether to skip Apache-specific httpd server setup, for example when using nginx.
+
+=item httpd_start
+
+When setting skip_apache, set this to the command to start your webserver. An example with nginx:
+
+ /usr/sbin/nginx -c __CAMP_PATH__/nginx/nginx.conf
+
+=item httpd_stop
+
+When setting skip_apache, set this to the command to stop your webserver. An example with nginx:
+
+ pid=`cat __CAMP_PATH__/var/run/nginx.pid 2>/dev/null` && kill $pid
+
+=item httpd_restart
+
+pid=`cat __CAMP_PATH__/var/run/nginx.pid 2>/dev/null` && kill -HUP $pid || /usr/sbin/nginx -c __CAMP_PATH__/nginx/nginx.conf
+
=item skip_ssl_cert_gen
A boolean (0/1) setting that determines whether to skip generation of a self-signed SSL certificate for the HTTP server.
@@ -967,6 +1009,24 @@ directly within a virtualhost's <Proxy balancer://...>...</Proxy> container. De
to using three mongrel listeners with ports incremented by one starting at the
mongrel_base_port.
+=item app_start
+
+When using an application server other than those natively supported in camps, set this to the command to start your application server. For example (using a custom startup script):
+
+ __CAMP_PATH__/bin/start-unicorn
+
+=item app_stop
+
+Command to stop your application server. An example for Ruby's Unicorn:
+
+ pid=`cat __CAMP_PATH__/var/run/unicorn.pid 2>/dev/null` && kill $pid
+
+=item app_restart
+
+Command to restart your application server. An example for Ruby's Unicorn:
+
+ pid=`cat __CAMP_PATH__/var/run/unicorn.pid 2>/dev/null` && kill -HUP $pid || __CAMP_PATH__/bin/start-unicorn
+
=item db_type
The type of database server used for the camp; will be either 'pg' for Postgres or 'mysql'
@@ -1828,12 +1888,15 @@ sub _ssl_private_key {
sub prepare_apache {
my $conf = config_hash();
- # create empty directories
- mkpath([ map { File::Spec->catfile( $conf->{httpd_path}, $_, ) } qw( conf logs run ) ]);
- # symlink to system-wide Apache modules
- symlink $conf->{httpd_lib_path}, File::Spec->catfile($conf->{httpd_path}, 'modules')
- or die "Couldn't symlink Apache modules directory\n";
+ unless ($conf->{skip_apache}) {
+ # create empty directories
+ mkpath([ map { File::Spec->catfile( $conf->{httpd_path}, $_, ) } qw( conf logs run ) ]);
+
+ # symlink to system-wide Apache modules
+ symlink $conf->{httpd_lib_path}, File::Spec->catfile($conf->{httpd_path}, 'modules')
+ or die "Couldn't symlink Apache modules directory\n";
+ }
# Create SSL certificate
unless ($conf->{skip_ssl_cert_gen}) {
@@ -1896,13 +1959,6 @@ when copied into the new camp itself. Thus, a file at /home/camp/some_type/etc/
would be registered in B<camp-config-files> with a path relative to etc/, or "blah/foo.conf",
and would be installed at /home/some_user/campNN/blah/foo.conf after parsing.
-One file is always parsed by default, regardless of specification in the config file:
-
- httpd/conf/httpd.conf
-
-This is the base Apache configuration, and Apache is thus always expected to live at httpd
-within a camp. You could theoretically change this in your camp, but do so at your peril.
-
Also, some assumptions are made about what files will be included if your camp uses
Interchange versus Rails:
@@ -2444,7 +2500,7 @@ sub db_connect {
sub _db_connect_pg {
my %opt = @_;
my $conf = config_hash();
- my $cmd = "psql -X -p $conf->{db_port} -U $opt{user} -d $opt{database}";
+ my $cmd = "psql -X -h $conf->{db_host} -p $conf->{db_port} -U $opt{user} -d $opt{database}";
print "Connecting to Postgres: $cmd\n";
open my $PSQL, "| $cmd"
or die "Error opening pipe to psql: $!\n";
@@ -2546,7 +2602,7 @@ sub _import_db_cmd_pg {
# But for newer ones, use that instead of template1 so we don't pollute the
# template db if something goes wrong in the import.
my $dbname = (db_version_pg() < 8.0) ? 'template1' : 'postgres';
- return "psql -X -p $conf->{db_port} -U postgres -d $dbname -f $script";
+ return "psql -X -h $conf->{db_host} -p $conf->{db_port} -U postgres -d $dbname -f $script";
}
sub _import_db_cmd_mysql {
@@ -2663,8 +2719,9 @@ sub server_control {
);
my $dbtype = camp_db_type();
- $services{ic} = \&ic_control if has_ic();
+ $services{ic} = \&ic_control if has_ic();
$services{rails} = \&rails_control if has_rails();
+ $services{app} = \&app_control if has_app();
$services{$dbtype} = $db_services{$dbtype};
delete $services{db} if $conf_hash->{skip_db};
@@ -2675,6 +2732,7 @@ sub server_control {
db
ic
rails
+ app
);
die "Invalid action '$action' specified!\n" unless $actions{$action};
@@ -2701,6 +2759,15 @@ sub server_control {
return scalar(@services_to_start);
}
+sub app_control {
+ my $action = shift;
+ my $conf = config_hash();
+
+ my $cmd = $conf->{"app_$action"};
+ $cmd and do_system_soft($cmd) == 0 and return 1;
+ return;
+}
+
sub rails_control {
my $action = shift;
my $conf = config_hash();
@@ -2767,7 +2834,7 @@ sub _db_control_pg {
die "Need db_data definition!\n"
unless defined $conf->{db_data}
and $conf->{db_data} =~ /\S/;
- my $cmd = "pg_ctl -D $conf->{db_data} -l $conf->{db_tmpdir}/pgstartup.log -m fast";
+ my $cmd = "PGHOST=$conf->{db_host} pg_ctl -D $conf->{db_data} -l $conf->{db_tmpdir}/pgstartup.log -m fast";
# Work around old pg_ctl's terrible -w implementation, as evidenced by
# this comment there: "FIXME: This is horribly misconceived."
my $manual_wait = (db_version_pg() < 8.0);
@@ -2782,22 +2849,25 @@ sub _db_control_pg {
sub httpd_control {
my $action = shift;
my $conf = config_hash();
- die "Need httpd_cmd_path definition!\n"
- unless defined $conf->{httpd_cmd_path}
- and $conf->{httpd_cmd_path} =~ /\S/;
- die "Need httpd_path definition!\n"
- unless defined $conf->{httpd_path}
- and $conf->{httpd_path} =~ /\S/;
- my $cmd = "$conf->{httpd_cmd_path} -d $conf->{httpd_path} -k $action";
- $cmd .= join('', map { " -D$_" } grep /\S/, split / /, $conf->{httpd_define})
- if $conf->{httpd_define};
- if (defined $conf->{httpd_specify_conf} and $conf->{httpd_specify_conf} =~ /\S/) {
- $cmd .= " -f $conf->{httpd_path}/$conf->{httpd_specify_conf}";
+ my $cmd = $conf->{"httpd_$action"};
+ if (!$conf->{skip_apache} and !$cmd) {
+ die "Need httpd_cmd_path definition!\n"
+ unless defined $conf->{httpd_cmd_path}
+ and $conf->{httpd_cmd_path} =~ /\S/;
+ die "Need httpd_path definition!\n"
+ unless defined $conf->{httpd_path}
+ and $conf->{httpd_path} =~ /\S/;
+
+ $cmd = "$conf->{httpd_cmd_path} -d $conf->{httpd_path} -k $action";
+ $cmd .= join('', map { " -D$_" } grep /\S/, split / /, $conf->{httpd_define})
+ if $conf->{httpd_define};
+ if (defined $conf->{httpd_specify_conf} and $conf->{httpd_specify_conf} =~ /\S/) {
+ $cmd .= " -f $conf->{httpd_path}/$conf->{httpd_specify_conf}";
+ }
}
- do_system_soft($cmd) == 0
- and return 1;
+ $cmd and do_system_soft($cmd) == 0 and return 1;
return;
}

No commit comments for this range

Something went wrong with that request. Please try again.