8 # Rename binary in process list to make init scripts saner
12 dbhost
=> "localhost",
30 "dbhost=s" => \
$args{dbhost
},
31 "dbport=s" => \
$args{dbport
},
32 "dbname=s" => \
$args{dbname
},
33 "dbrootuser=s" => \
$args{dbrootuser
},
34 "dbrootpassword:s" => \
$args{dbrootpass
},
35 "dbuser=s" => \
$args{dbuser
},
36 "dbpassword:s" => \
$args{dbpass
},
38 "verbose" => \
$opt_verbose,
40 "noschemabump" => \
$opt_noschemabump,
42 "plugins=s" => \
$plugins,
47 # Be nice about what the default admin user is called.
48 if(!defined($args{dbrootuser
})) {
49 $args{dbrootuser
} = 'root' if $dbtype =~ /MySQL/i;
50 $args{dbrootuser
} = 'postgres' if $dbtype =~ /Postgres/i;
52 # Saner port management.
53 # This should default to the UNIX sockets on localhost
54 if(!defined($args{dbport
}) and $args{dbhost
} != "localhost" and $args{dbhost
} != "127.0.0.1") {
55 $args{dbport
} = '3306' if $dbtype =~ /MySQL/i;
56 $args{dbport
} = '5432' if $dbtype =~ /Postgres/i;
61 Usage: mogdbsetup [opts]
66 ============ ===========================================
67 --verbose <off> Be verbose about what\'s happening.
69 --dbhost= localhost hostname or IP to database server.
71 --dbport= dbd default port number to database server.
73 --dbname= mogilefs database name to create/upgrade.
75 --dbrootuser= root Database administrator username. Only needed
76 for initial setup, not subsequent upgrades.
78 --dbrootpass= <blank> Database administrator password. Only needed
79 for initial setup, not subsequent upgrades.
81 --dbuser= mogile Regular database user to create and/or use
82 for MogileFS database. This is what the
83 mogilefsd trackers connect as.
85 --dbpass= <blank> You should change this, especially if your
86 database servers are accessible to other users
87 on the network. But they shouldn't be
88 if you're running MogileFS, because MogileFS
89 assumes your network is closed.
91 --type= MySQL Which MogileFS::Store implementation to use.
92 Available: MySQL, Postgres
94 --yes Run without questions.
99 my $sclass = "MogileFS::Store::$dbtype";
100 eval "use $sclass; 1;" or die "Failed to load $sclass: $@";
102 foreach my $plugin (split /\s*,\s*/, $plugins) {
103 eval "use MogileFS::Plugin::$plugin; 1;" or die "Failed to load plugin $plugin: $@";
106 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);
108 $sclass->on_status(\
&status
);
109 $sclass->on_confirm(\
&confirm
);
111 MogileFS
::Config
->load_config;
113 my $sto = $sclass->new_from_mogdbsetup(
114 map { $_ => $args{$_} }
115 qw(dbhost dbport dbname
116 dbrootuser dbrootpass
122 or die "Database upgrade failed.\n";
124 my $latestver = MogileFS
::Store
->latest_schema_version;
125 if ($opt_noschemabump) {
126 warn "\n*\n* Per your request, NOT UPGRADING to $latestver. I assume you understand why.\n*\n";
128 $sto->set_schema_vesion($latestver);
132 warn "Done.\n" if $opt_verbose;
135 ############################################################################
140 $def = 1 unless defined $def;
142 return 1 if $opt_yes;
143 my $deftext = $def ?
"[Y/n]" : "[N/y]";
145 print "\n$q $deftext: ";
147 if ($ans =~ /^\s*$/) {
148 die "Stopped.\n" unless $def;
151 return 1 if $ans =~ /^y/i;
156 warn "$_[0]\n" if $opt_verbose;