2011-05-02 01:36:11 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use FindBin qw($Bin);
|
|
|
|
use Getopt::Long;
|
2012-03-26 20:57:53 +00:00
|
|
|
require "$Bin/misc/devlib.pl";
|
2013-01-22 20:47:42 +00:00
|
|
|
require "$Bin/misc/get_closure.pl";
|
2011-05-02 01:36:11 +00:00
|
|
|
|
|
|
|
sub usage {
|
2013-06-19 06:14:36 +00:00
|
|
|
die "Usage: dev-server [OPTS] [<portnumber>] -- [other_blobserver_opts]\n\nWhere OPTS include:\n [--wipe] [--mongo|--mysql|--postgres] [--tls] [--fullclosure] " .
|
2013-06-19 13:36:59 +00:00
|
|
|
"[--all] [--nobuild] [--staticres] [--KBps=<number>] " .
|
2013-06-19 06:14:36 +00:00
|
|
|
"[--latency_ms=<number>] [--fast] [--verbose] [--hostname=<name>]\n";
|
2011-05-02 01:36:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 07:14:26 +00:00
|
|
|
chdir $Bin or die;
|
|
|
|
|
2012-12-12 04:36:42 +00:00
|
|
|
my $opt_KBps = 150; # if non-zero, kBps to throttle connections
|
|
|
|
my $opt_latency_ms = 90; # added latency in millisecond
|
|
|
|
my $opt_fast; # shortcut to disable throttling
|
|
|
|
|
2011-05-14 23:40:16 +00:00
|
|
|
my $opt_all; # listen on all interfaces
|
2013-01-27 22:05:32 +00:00
|
|
|
my $opt_hostname; # hostname to advertise, else `hostname` is used
|
2012-12-12 04:36:42 +00:00
|
|
|
my $opt_nobuild;
|
2013-06-19 06:14:36 +00:00
|
|
|
my $opt_fullclosure; # make all of closure available
|
2012-12-12 04:36:42 +00:00
|
|
|
my $opt_staticres; # use static resources, not those on disk
|
|
|
|
my $opt_tls;
|
|
|
|
my $opt_wipe;
|
2013-01-20 22:08:55 +00:00
|
|
|
my $opt_verbose;
|
2011-11-26 20:30:22 +00:00
|
|
|
|
|
|
|
# keep indexes in memory only. often used with --wipe, but not
|
|
|
|
# necessarily. if --wipe isn't used, all blobs are re-indexed
|
|
|
|
# on start-up.
|
|
|
|
my $opt_memory;
|
2011-12-25 20:30:56 +00:00
|
|
|
my $opt_mongo;
|
2012-11-03 18:58:50 +00:00
|
|
|
my $opt_postgres;
|
2012-02-29 07:14:26 +00:00
|
|
|
my $opt_mysql;
|
2011-05-14 23:40:16 +00:00
|
|
|
GetOptions("wipe" => \$opt_wipe,
|
2011-11-16 10:41:38 +00:00
|
|
|
"tls" => \$opt_tls,
|
2011-05-14 23:40:16 +00:00
|
|
|
"all" => \$opt_all,
|
2011-07-18 00:36:56 +00:00
|
|
|
"nobuild" => \$opt_nobuild,
|
2011-11-26 20:30:22 +00:00
|
|
|
"memory" => \$opt_memory,
|
2011-12-25 20:30:56 +00:00
|
|
|
"mongo" => \$opt_mongo,
|
2012-11-03 18:58:50 +00:00
|
|
|
"postgres" => \$opt_postgres,
|
2012-02-29 07:14:26 +00:00
|
|
|
"mysql" => \$opt_mysql,
|
2012-02-29 16:01:59 +00:00
|
|
|
"staticres" => \$opt_staticres,
|
2012-12-12 04:36:42 +00:00
|
|
|
"KBps=i" => \$opt_KBps,
|
|
|
|
"latency_ms=i" => \$opt_latency_ms,
|
|
|
|
"fast" => \$opt_fast,
|
2013-01-20 22:08:55 +00:00
|
|
|
"verbose" => \$opt_verbose,
|
2013-01-27 22:05:32 +00:00
|
|
|
"hostname=s" => \$opt_hostname,
|
2013-06-19 06:14:36 +00:00
|
|
|
"fullclosure" => \$opt_fullclosure,
|
2011-05-14 23:40:16 +00:00
|
|
|
)
|
2011-05-02 01:36:11 +00:00
|
|
|
or usage();
|
|
|
|
|
2012-11-03 18:58:50 +00:00
|
|
|
$opt_memory = 1 unless $opt_memory || $opt_mongo || $opt_postgres || $opt_mysql;
|
2012-02-29 07:14:26 +00:00
|
|
|
|
2011-05-09 19:22:31 +00:00
|
|
|
my $port = shift;
|
2011-05-09 21:17:11 +00:00
|
|
|
$port = "3179" unless defined($port);
|
2011-05-02 01:36:11 +00:00
|
|
|
usage() unless $port =~ /^\d+$/;
|
|
|
|
|
2012-12-12 04:36:42 +00:00
|
|
|
unless ($opt_fast) {
|
|
|
|
$ENV{DEV_THROTTLE_KBPS} = $opt_KBps;
|
|
|
|
$ENV{DEV_THROTTLE_LATENCY_MS} = $opt_latency_ms;
|
|
|
|
}
|
|
|
|
|
2013-01-29 15:41:02 +00:00
|
|
|
$ENV{CAMLI_HTTP_DEBUG} = 1 if $opt_verbose;
|
2013-01-20 22:08:55 +00:00
|
|
|
|
2012-03-26 20:57:53 +00:00
|
|
|
my $camlistored;
|
2013-03-07 20:44:28 +00:00
|
|
|
my $camtool; # closure to return path
|
2012-03-26 20:57:53 +00:00
|
|
|
if ($opt_nobuild) {
|
|
|
|
$camlistored = find_bin("./server/camlistored");
|
2013-03-07 20:44:28 +00:00
|
|
|
$camtool = sub { scalar find_bin("./cmd/camtool") };
|
2012-03-26 20:57:53 +00:00
|
|
|
} else {
|
|
|
|
$camlistored = build_bin("./server/camlistored");
|
2013-03-07 20:44:28 +00:00
|
|
|
$camtool = sub { scalar build_bin("./cmd/camtool") };
|
2011-07-18 00:36:56 +00:00
|
|
|
}
|
2011-05-02 01:36:11 +00:00
|
|
|
|
2011-09-30 03:29:36 +00:00
|
|
|
my $root = "/tmp/camliroot-$ENV{USER}/port$port/";
|
2011-05-02 01:36:11 +00:00
|
|
|
if ($opt_wipe && -d $root) {
|
|
|
|
print "Wiping $root\n";
|
|
|
|
system("rm", "-rf", $root) and die "Failed to wipe $root.\n";
|
|
|
|
}
|
2011-05-23 04:22:21 +00:00
|
|
|
|
|
|
|
my $suffixdir = sub {
|
|
|
|
my $suffix = shift;
|
|
|
|
my $root = "$root/$suffix";
|
|
|
|
unless (-d $root) {
|
|
|
|
system("mkdir", "-p", $root) and die "Failed to create $root.\n";
|
2011-05-21 16:26:20 +00:00
|
|
|
}
|
2011-05-23 04:22:21 +00:00
|
|
|
return $root;
|
|
|
|
};
|
2011-05-02 01:36:11 +00:00
|
|
|
|
2011-07-02 02:16:58 +00:00
|
|
|
my $DBNAME = "devcamli$ENV{USER}";
|
2011-05-02 01:36:11 +00:00
|
|
|
my @opts;
|
|
|
|
if ($opt_wipe) {
|
|
|
|
push @opts, "-wipe";
|
|
|
|
} else {
|
|
|
|
push @opts, "-ignoreexists";
|
|
|
|
}
|
|
|
|
|
2011-12-25 20:30:56 +00:00
|
|
|
$ENV{"CAMLI_MYSQL_ENABLED"} = "false";
|
|
|
|
$ENV{"CAMLI_MONGO_ENABLED"} = "false";
|
2012-11-03 18:58:50 +00:00
|
|
|
$ENV{"CAMLI_POSTGRES_ENABLED"} = "false";
|
2011-11-26 20:30:22 +00:00
|
|
|
if ($opt_memory) {
|
|
|
|
$ENV{"CAMLI_INDEXER_PATH"} = "/index-mem/";
|
2012-11-03 18:58:50 +00:00
|
|
|
} elsif ($opt_mongo) {
|
|
|
|
$ENV{"CAMLI_MONGO_ENABLED"} = "true";
|
|
|
|
$ENV{"CAMLI_INDEXER_PATH"} = "/index-mongo/";
|
|
|
|
if ($opt_wipe) {
|
|
|
|
$ENV{"CAMLI_MONGO_WIPE"} = "true";
|
2011-12-25 20:30:56 +00:00
|
|
|
} else {
|
2012-11-03 18:58:50 +00:00
|
|
|
$ENV{"CAMLI_MONGO_WIPE"} = "false";
|
2011-12-25 20:30:56 +00:00
|
|
|
}
|
2012-11-03 18:58:50 +00:00
|
|
|
} elsif ($opt_postgres) {
|
|
|
|
$ENV{"CAMLI_POSTGRES_ENABLED"} = "true";
|
|
|
|
$ENV{"CAMLI_INDEXER_PATH"} = "/index-postgres/";
|
2013-03-07 20:44:28 +00:00
|
|
|
system($camtool->(),
|
|
|
|
"dbinit",
|
2013-06-25 04:27:23 +00:00
|
|
|
"-dbtype=postgres",
|
2012-11-03 18:58:50 +00:00
|
|
|
"-user=postgres",
|
|
|
|
"-password=postgres",
|
|
|
|
"-host=localhost",
|
2013-03-07 20:44:28 +00:00
|
|
|
"-dbname=$DBNAME",
|
|
|
|
@opts) and die "Failed to run camtool dbinit.\n";
|
2012-11-03 18:58:50 +00:00
|
|
|
} else {
|
|
|
|
$ENV{"CAMLI_MYSQL_ENABLED"} = "true";
|
|
|
|
$ENV{"CAMLI_INDEXER_PATH"} = "/index-mysql/";
|
2013-03-07 20:44:28 +00:00
|
|
|
system($camtool->(),
|
|
|
|
"dbinit",
|
2012-11-03 18:58:50 +00:00
|
|
|
"-user=root",
|
|
|
|
"-password=root",
|
|
|
|
"-host=localhost",
|
2013-03-07 20:44:28 +00:00
|
|
|
"-dbname=$DBNAME",
|
|
|
|
@opts) and die "Failed to run camtool dbinit.\n";
|
2011-11-26 20:30:22 +00:00
|
|
|
}
|
2011-05-02 01:36:11 +00:00
|
|
|
|
2011-05-14 23:40:16 +00:00
|
|
|
my $base = "http://localhost:$port";
|
|
|
|
my $listen = "127.0.0.1:$port";
|
|
|
|
if ($opt_all) {
|
|
|
|
$listen = "0.0.0.0:$port";
|
2013-01-27 22:05:32 +00:00
|
|
|
my $host = $opt_hostname || `hostname`;
|
2011-05-14 23:40:16 +00:00
|
|
|
chomp $host;
|
|
|
|
$base = "http://$host:$port";
|
|
|
|
}
|
2011-11-16 10:41:38 +00:00
|
|
|
if ($opt_tls) {
|
2011-11-28 17:45:08 +00:00
|
|
|
$base =~ s/^http/https/;
|
2011-11-16 10:41:38 +00:00
|
|
|
}
|
2011-05-14 23:40:16 +00:00
|
|
|
|
2011-11-16 10:41:38 +00:00
|
|
|
$ENV{CAMLI_TLS} = "false";
|
|
|
|
if ($opt_tls) {
|
|
|
|
$ENV{CAMLI_TLS} = "true";
|
|
|
|
}
|
2013-06-19 06:14:36 +00:00
|
|
|
$ENV{CAMLI_DEV_CAMLI_ROOT} = $Bin;
|
2011-05-14 23:40:16 +00:00
|
|
|
$ENV{CAMLI_BASEURL} = $base;
|
2012-04-28 01:49:01 +00:00
|
|
|
$ENV{CAMLI_AUTH} = "userpass:camlistore:pass$port:+localhost";
|
2011-06-09 23:09:21 +00:00
|
|
|
$ENV{CAMLI_ADVERTISED_PASSWORD} = "pass$port"; # public password
|
2011-05-23 04:22:21 +00:00
|
|
|
$ENV{CAMLI_ROOT} = $suffixdir->("bs");
|
|
|
|
$ENV{CAMLI_ROOT_SHARD1} = $suffixdir->("s1");
|
|
|
|
$ENV{CAMLI_ROOT_SHARD2} = $suffixdir->("s2");
|
|
|
|
$ENV{CAMLI_ROOT_REPLICA1} = $suffixdir->("r1");
|
|
|
|
$ENV{CAMLI_ROOT_REPLICA2} = $suffixdir->("r2");
|
|
|
|
$ENV{CAMLI_ROOT_REPLICA3} = $suffixdir->("r3");
|
2011-06-04 16:58:50 +00:00
|
|
|
$ENV{CAMLI_ROOT_CACHE} = $suffixdir->("cache");
|
2013-06-15 22:05:27 +00:00
|
|
|
$ENV{CAMLI_ROOT_ENCMETA} = $suffixdir->("encmeta");
|
|
|
|
$ENV{CAMLI_ROOT_ENCBLOB} = $suffixdir->("encblob");
|
2011-05-02 01:36:11 +00:00
|
|
|
$ENV{CAMLI_PORT} = $port;
|
2012-02-29 07:42:28 +00:00
|
|
|
$ENV{CAMLI_SECRET_RING} = "$Bin/pkg/jsonsign/testdata/test-secring.gpg";
|
2011-07-02 02:16:58 +00:00
|
|
|
$ENV{CAMLI_DBNAME} = $DBNAME;
|
2011-06-18 19:04:11 +00:00
|
|
|
|
2012-11-20 15:19:50 +00:00
|
|
|
my $templatedir = "$Bin/dev-server-template";
|
|
|
|
if ($opt_wipe && -d $templatedir) {
|
|
|
|
my $blobs = "$ENV{CAMLI_ROOT}/sha1";
|
|
|
|
system("cp", "-a", $templatedir, $blobs) and die "Failed to cp template blobs.\n";
|
|
|
|
}
|
|
|
|
|
2011-06-18 19:04:11 +00:00
|
|
|
# To use resources from disk, instead of the copies linked into the
|
|
|
|
# binary:
|
2013-06-19 06:14:36 +00:00
|
|
|
if ($opt_fullclosure) {
|
|
|
|
if (-e "$Bin/tmp/closure-lib/.svn") {
|
|
|
|
system("rm", "-rf", "$Bin/tmp/closure-lib") and die "Failed to remove the svn checkout of the closure-lib.\n";
|
2012-12-03 22:46:08 +00:00
|
|
|
}
|
2013-06-19 06:14:36 +00:00
|
|
|
get_closure_lib();
|
|
|
|
get_closure_compiler();
|
|
|
|
chdir $Bin or die;
|
|
|
|
$ENV{CAMLI_DEV_CLOSURE_DIR} = "$Bin/tmp/closure-lib/closure";
|
2012-02-29 16:01:59 +00:00
|
|
|
}
|
2011-06-18 19:04:11 +00:00
|
|
|
|
2012-12-03 22:46:08 +00:00
|
|
|
print "Starting dev server on $base/ui/ with password \"pass$port\"\n";
|
|
|
|
|
2012-03-26 20:57:53 +00:00
|
|
|
exec("$camlistored",
|
2011-05-02 01:36:11 +00:00
|
|
|
"-configfile=$Bin/config/dev-server-config.json",
|
2011-05-14 23:40:16 +00:00
|
|
|
"-listen=$listen",
|
2011-05-02 01:36:11 +00:00
|
|
|
@ARGV);
|
2012-03-06 00:36:28 +00:00
|
|
|
die "exec failure: $!\n";
|