2011-05-02 01:36:11 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use FindBin qw($Bin);
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
die "Usage: dev-server [--wipe] <portnumber> -- [other_blobserver_opts]";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $opt_wipe;
|
2011-05-14 23:40:16 +00:00
|
|
|
my $opt_all; # listen on all interfaces
|
|
|
|
GetOptions("wipe" => \$opt_wipe,
|
|
|
|
"all" => \$opt_all,
|
|
|
|
)
|
2011-05-02 01:36:11 +00:00
|
|
|
or usage();
|
|
|
|
|
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+$/;
|
|
|
|
|
|
|
|
system("./build.pl", "server/go/camlistored") and die "Failed to build camlistored";
|
|
|
|
system("./build.pl", "clients/go/camdbinit") and die "Failed to build camdbinit";
|
|
|
|
|
|
|
|
my $root = "/tmp/camliroot/port$port/";
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
system("./clients/go/camdbinit/camdbinit",
|
|
|
|
"-user=root",
|
|
|
|
"-password=root",
|
|
|
|
"-host=localhost",
|
|
|
|
"-database=$DBNAME",
|
|
|
|
@opts) and die "Failed to run camdbinit.\n";
|
|
|
|
|
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";
|
|
|
|
my $host = `hostname`;
|
|
|
|
chomp $host;
|
|
|
|
$base = "http://$host:$port";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "Starting dev server on $base/ui/ with password \"pass$port\"\n";
|
2011-05-02 01:36:11 +00:00
|
|
|
|
2011-05-14 23:40:16 +00:00
|
|
|
$ENV{CAMLI_BASEURL} = $base;
|
2011-05-02 01:36:11 +00:00
|
|
|
$ENV{CAMLI_PASSWORD} = "pass$port";
|
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");
|
2011-05-02 01:36:11 +00:00
|
|
|
$ENV{CAMLI_PORT} = $port;
|
2011-05-02 04:23:31 +00:00
|
|
|
$ENV{CAMLI_SECRET_RING} = "$Bin/lib/go/camli/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
|
|
|
|
|
|
|
# To use resources from disk, instead of the copies linked into the
|
|
|
|
# binary:
|
|
|
|
$ENV{CAMLI_DEV_UI_FILES} = "$FindBin::Bin/server/go/camlistored/ui"; # set in server/go/camlistored/ui/fileembed.go
|
|
|
|
|
2011-05-02 01:36:11 +00:00
|
|
|
exec("$FindBin::Bin/server/go/camlistored/camlistored",
|
|
|
|
"-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);
|