-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathn1repl_command.pl
More file actions
executable file
·95 lines (67 loc) · 1.8 KB
/
n1repl_command.pl
File metadata and controls
executable file
·95 lines (67 loc) · 1.8 KB
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
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use FindBin;
use lib "$FindBin::Bin/extlib/lib/perl5";
use lib "$FindBin::Bin/lib";
use Getopt::Long;
use Pod::Usage;
use Data::Dumper;
use N1Repl::Config;
use N1Repl::CommandPublisher;
++$|; # auto flush
my $daemonize = 0;
my $config_file;
my $command;
my %params;
sub command_options {
my ($name, $value) = @_;
$params{$name} = $value;
}
Getopt::Long::Configure('no_ignore_case', 'gnu_compat');
my $r = GetOptions(
'config=s' => \$config_file,
'h|help' => \my $help,
'<>' => sub { $command = shift },
'orig_master_host=s' => \&command_options,
'orig_master_port=i' => \&command_options,
'orig_master_log_file=s' => \&command_options,
'orig_master_log_pos=i' => \&command_options,
'new_master_host=s' => \&command_options,
'new_master_port=i' => \&command_options,
'new_master_log_file=s' => \&command_options,
'new_master_log_pos=i' => \&command_options,
);
if ($help || !$config_file || !$command) {
pod2usage(-verbose=>2, -exitval=>0);
}
my $config = N1Repl::Config->new()->load($config_file);
my $publisher = $config->command_publisher;
my $cmd = $publisher->make_command(uc($command));
unless ($cmd) {
print STDERR "unknown command $command\n";
exit(1);
}
unless ($publisher->publish($cmd, %params)) {
print "failed\n";
exit(2);
}
__END__
=head1 NAME
n1repl_command.pl
=head1 SYNOPSIS
% n1repl_command_command.pl --conf=conf.yaml start
% n1repl_command_command.pl --conf=conf.yaml stop
=head1 DESCRIPTION
master n : slave 1 replication commander for mysql
=head1 OPTIONS
=over 4
=item -h --help
Display help
=back
=head1 AUTHOR
do_aki
=head1 LICENSE
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.