7 # Rename binary in process list to make init scripts saner
11 dbhost
=> "localhost",
29 "dbhost=s" => \
$args{dbhost
},
30 "dbport=s" => \
$args{dbport
},
31 "dbname=s" => \
$args{dbname
},
32 "dbrootuser=s" => \
$args{dbrootuser
},
33 "dbrootpassword=s" => \
$args{dbrootpass
},
34 "dbuser=s" => \
$args{dbuser
},
35 "dbpassword=s" => \
$args{dbpass
},
37 "verbose" => \
$opt_verbose,
39 "noschemabump" => \
$opt_noschemabump,
41 "plugins=s" => \
$plugins,
46 # Be nice about what the default admin user is called.
47 if(!defined($args{dbrootuser
})) {
48 $args{dbrootuser
} = 'root' if $dbtype =~ /MySQL/i;
49 $args{dbrootuser
} = 'postgres' if $dbtype =~ /Postgres/i;
51 # Saner port management.
52 # This should default to the UNIX sockets on localhost
53 if(!defined($args{dbport
}) and $args{dbhost
} != "localhost" and $args{dbhost
} != "127.0.0.1") {
54 $args{dbport
} = '3306' if $dbtype =~ /MySQL/i;
55 $args{dbport
} = '5432' if $dbtype =~ /Postgres/i;
60 Usage: mogdbsetup [opts]
65 ============ ===========================================
66 --verbose <off> Be verbose about what\'s happening.
68 --dbhost= localhost hostname or IP to database server.
70 --dbport= dbd default port number to database server.
72 --dbname= mogilefs database name to create/upgrade.
74 --dbrootuser= root Database administrator username. Only needed
75 for initial setup, not subsequent upgrades.
77 --dbrootpass= <blank> Database administrator password. Only needed
78 for initial setup, not subsequent upgrades.
80 --dbuser= mogile Regular database user to create and/or use
81 for MogileFS database. This is what the
82 mogilefsd trackers connect as.
84 --dbpass= <blank> You should change this, especially if your
85 database servers are accessible to other users
86 on the network. But they shouldn't be
87 if you're running MogileFS, because MogileFS
88 assumes your network is closed.
90 --type= MySQL Which MogileFS::Store implementation to use.
91 Available: MySQL, Postgres
93 --yes Run without questions.
98 my $sclass = "MogileFS::Store::$dbtype";
99 eval "use $sclass; 1;" or die "Failed to load $sclass: $@";
101 foreach my $plugin (split /\s*,\s*/, $plugins) {
102 eval "use MogileFS::Plugin::$plugin; 1;" or die "Failed to load plugin $plugin: $@";
105 confirm
("This will attempt to setup or upgrade your MogileFS database.\nIt won't destroy existing data.\nRun with --help for more information. Run with --yes to shut up these prompts.\n\nContinue?", 0);
107 $sclass->on_status(\
&status
);
108 $sclass->on_confirm(\
&confirm
);
110 my $sto = $sclass->new_from_mogdbsetup(
111 map { $_ => $args{$_} }
112 qw(dbhost dbport dbname
113 dbrootuser dbrootpass
119 or die "Database upgrade failed.\n";
121 my $latestver = MogileFS
::Store
->latest_schema_version;
122 if ($opt_noschemabump) {
123 warn "\n*\n* Per your request, NOT UPGRADING to $latestver. I assume you understand why.\n*\n";
125 $sto->set_schema_vesion($latestver);
129 warn "Done.\n" if $opt_verbose;
132 ############################################################################
137 $def = 1 unless defined $def;
139 return 1 if $opt_yes;
140 my $deftext = $def ?
"[Y/n]" : "[N/y]";
142 print "\n$q $deftext: ";
144 if ($ans =~ /^\s*$/) {
145 die "Stopped.\n" unless $def;
148 return 1 if $ans =~ /^y/i;
153 warn "$_[0]\n" if $opt_verbose;