2011-03-05 23:31:54 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use FindBin;
|
|
|
|
use Getopt::Long;
|
|
|
|
use DBI;
|
|
|
|
|
|
|
|
sub usage {
|
2011-03-19 08:30:18 +00:00
|
|
|
die "Usage: dev-indexer [--wipe] <portnumber> -- [other_blobserver_opts]";
|
2011-03-05 23:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $opt_wipe;
|
|
|
|
GetOptions("wipe" => \$opt_wipe)
|
|
|
|
or usage();
|
|
|
|
|
|
|
|
my $port = shift || "3200";
|
|
|
|
usage() unless $port =~ /^\d+$/;
|
|
|
|
|
2011-03-30 03:29:32 +00:00
|
|
|
system("./build.pl", "server/go/camlistored") and die "Failed to build.\n";
|
2011-03-05 23:31:54 +00:00
|
|
|
|
|
|
|
# NOTE: Root required but not used by indexer blobserver
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
unless (-d $root) {
|
|
|
|
system("mkdir", "-p", $root) and die "Failed to create $root.\n";
|
|
|
|
}
|
|
|
|
|
2011-03-13 01:40:42 +00:00
|
|
|
my $DBNAME = "devcamlistore";
|
|
|
|
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:database=mysql", "root", "root") or
|
|
|
|
die "Failed to connect to MySQL on localhost with user/pass of root/root.\n";
|
|
|
|
|
|
|
|
my $camdb = DBI->connect("DBI:mysql:database=$DBNAME", "root", "root", {
|
|
|
|
PrintWarn => 0,
|
|
|
|
PrintError => 0,
|
|
|
|
});
|
|
|
|
unless ($camdb) {
|
|
|
|
print "Database '$DBNAME' doesn't exist; assuming --wipe and initializing.\n";
|
|
|
|
$opt_wipe = 1;
|
|
|
|
}
|
|
|
|
|
2011-03-05 23:31:54 +00:00
|
|
|
if ($opt_wipe) {
|
2011-03-13 01:40:42 +00:00
|
|
|
system("mysqladmin", "-uroot", "-proot", "--force", "drop", "$DBNAME");
|
|
|
|
system("mysqladmin", "-uroot", "-proot", "create", "$DBNAME") and die "Could not create MySQL database on localhost.\n";
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:database=$DBNAME", "root", "root", {
|
2011-03-05 23:31:54 +00:00
|
|
|
"RaiseError" => 1,
|
|
|
|
}) or die "Failed to connect to MySQL on localhost.\n";
|
|
|
|
|
|
|
|
# Begin schema creation.
|
|
|
|
$dbh->do("CREATE TABLE blobs (".
|
2011-03-13 22:33:14 +00:00
|
|
|
"blobref VARCHAR(128) NOT NULL PRIMARY KEY, ".
|
2011-03-05 23:31:54 +00:00
|
|
|
"size INTEGER NOT NULL, ".
|
|
|
|
"type VARCHAR(100)".
|
|
|
|
")");
|
2011-03-13 19:18:00 +00:00
|
|
|
|
|
|
|
$dbh->do("CREATE TABLE claims (".
|
|
|
|
"blobref VARCHAR(128) NOT NULL PRIMARY KEY, ".
|
|
|
|
"signer VARCHAR(128) NOT NULL, ".
|
|
|
|
"date VARCHAR(40) NOT NULL, ".
|
|
|
|
"INDEX (signer, date), ".
|
|
|
|
"unverified CHAR(1) NULL, ".
|
|
|
|
"claim VARCHAR(50) NOT NULL, ".
|
|
|
|
"permanode VARCHAR(128) NOT NULL, ".
|
2011-03-14 02:12:11 +00:00
|
|
|
"INDEX (permanode, signer, date), ".
|
2011-03-13 19:18:00 +00:00
|
|
|
"attr VARCHAR(128) NULL, ".
|
|
|
|
"value VARCHAR(128) NULL ".
|
|
|
|
")");
|
2011-03-13 22:33:14 +00:00
|
|
|
|
|
|
|
$dbh->do("CREATE TABLE permanodes (".
|
|
|
|
"blobref VARCHAR(128) NOT NULL PRIMARY KEY, ".
|
|
|
|
"unverified CHAR(1) NULL, ".
|
|
|
|
"signer VARCHAR(128) NOT NULL DEFAULT '', ".
|
|
|
|
"lastmod VARCHAR(40) NOT NULL DEFAULT '', ".
|
|
|
|
"INDEX (signer, lastmod) ".
|
|
|
|
")");
|
2011-03-05 23:31:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 03:29:32 +00:00
|
|
|
print "Starting indexer with indexer on http://localhost:$port/ in $root\n";
|
2011-03-05 23:31:54 +00:00
|
|
|
|
|
|
|
$ENV{CAMLI_PASSWORD} = "pass$port";
|
2011-03-30 03:29:32 +00:00
|
|
|
exec("$FindBin::Bin/server/go/camlistored/camlistored",
|
2011-03-05 23:31:54 +00:00
|
|
|
"-root=$root", # NOTE: Root required but not used by indexer blobserver
|
|
|
|
"-listen=:$port",
|
|
|
|
"-devmysqlindexer",
|
|
|
|
@ARGV);
|