forked from perkeep/perkeep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev-server
executable file
·148 lines (130 loc) · 3.95 KB
/
dev-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/perl
use strict;
use FindBin qw($Bin);
use Getopt::Long;
require "$Bin/misc/devlib.pl";
sub usage {
die "Usage: dev-server [--wipe] [--mongo|--memory] [--tls] <portnumber> -- [other_blobserver_opts]";
}
chdir $Bin or die;
my $opt_wipe;
my $opt_tls;
my $opt_nobuild;
my $opt_all; # listen on all interfaces
my $opt_staticres; # use static resources, not those on disk
# 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;
my $opt_mongo;
my $opt_mysql;
GetOptions("wipe" => \$opt_wipe,
"tls" => \$opt_tls,
"all" => \$opt_all,
"nobuild" => \$opt_nobuild,
"memory" => \$opt_memory,
"mongo" => \$opt_mongo,
"mysql" => \$opt_mysql,
"staticres" => \$opt_staticres,
)
or usage();
$opt_memory = 1 unless $opt_memory || $opt_mongo || $opt_mysql;
my $port = shift;
$port = "3179" unless defined($port);
usage() unless $port =~ /^\d+$/;
unless ($ENV{GOPATH}) {
$ENV{GOPATH} = "$Bin/gopath"
}
my $camlistored;
my $camdbinit;
if ($opt_nobuild) {
$camlistored = find_bin("./server/camlistored");
$camdbinit = find_bin("./cmd/camdbinit");
} else {
$camlistored = build_bin("./server/camlistored");
$camdbinit = build_bin("./cmd/camdbinit");
}
my $root = "/tmp/camliroot-$ENV{USER}/port$port/";
if ($opt_wipe && -d $root) {
print "Wiping $root\n";
system("rm", "-rf", $root) and die "Failed to wipe $root.\n";
}
my $suffixdir = sub {
my $suffix = shift;
my $root = "$root/$suffix";
unless (-d $root) {
system("mkdir", "-p", $root) and die "Failed to create $root.\n";
}
return $root;
};
my $DBNAME = "devcamli$ENV{USER}";
my @opts;
if ($opt_wipe) {
push @opts, "-wipe";
} else {
push @opts, "-ignoreexists";
}
$ENV{"CAMLI_MYSQL_ENABLED"} = "false";
$ENV{"CAMLI_MONGO_ENABLED"} = "false";
if ($opt_memory) {
$ENV{"CAMLI_INDEXER_PATH"} = "/index-mem/";
} else {
if ($opt_mongo) {
$ENV{"CAMLI_MONGO_ENABLED"} = "true";
$ENV{"CAMLI_INDEXER_PATH"} = "/index-mongo/";
# TODO(mpl): is this too hackish?
if ($opt_wipe) {
$ENV{"CAMLI_MONGO_WIPE"} = "true";
} else {
$ENV{"CAMLI_MONGO_WIPE"} = "false";
}
} else {
$ENV{"CAMLI_MYSQL_ENABLED"} = "true";
$ENV{"CAMLI_INDEXER_PATH"} = "/index-mysql/";
system("$camdbinit",
"-user=root",
"-password=root",
"-host=localhost",
"-database=$DBNAME",
@opts) and die "Failed to run camdbinit.\n";
}
}
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";
}
if ($opt_tls) {
$base =~ s/^http/https/;
}
print "Starting dev server on $base/ui/ with password \"pass$port\"\n";
$ENV{CAMLI_TLS} = "false";
if ($opt_tls) {
$ENV{CAMLI_TLS} = "true";
}
$ENV{CAMLI_BASEURL} = $base;
$ENV{CAMLI_AUTH} = "userpass:camlistore:pass$port:+localhost";
$ENV{CAMLI_ADVERTISED_PASSWORD} = "pass$port"; # public password
$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");
$ENV{CAMLI_ROOT_CACHE} = $suffixdir->("cache");
$ENV{CAMLI_PORT} = $port;
$ENV{CAMLI_SECRET_RING} = "$Bin/pkg/jsonsign/testdata/test-secring.gpg";
$ENV{CAMLI_DBNAME} = $DBNAME;
# To use resources from disk, instead of the copies linked into the
# binary:
unless ($opt_staticres) {
$ENV{CAMLI_DEV_UI_FILES} = "$FindBin::Bin/server/camlistored/ui"; # set in server/camlistored/ui/fileembed.go
}
exec("$camlistored",
"-configfile=$Bin/config/dev-server-config.json",
"-listen=$listen",
@ARGV);
die "exec failure: $!\n";