blob: 5dcdc47b913a273f7da7e103f09fba77619e9f90 (
plain)
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
|
#!/usr/bin/perl
use strict;
use lib "/opt/vyatta/share/perl5/";
use VyattaClusterConfig;
my $HA_DIR = "/etc/ha.d";
my $HA_INIT = "/etc/init.d/heartbeat";
my $SERVICE_DIR = "/etc/init.d";
my $config = new VyattaClusterConfig;
$config->setup("cluster");
if ($config->isEmpty()) {
# config is empty => deleted.
# shutdown clustering.
system("$HA_INIT stop");
$config->del_watchlink_exclude();
exit 0;
}
my ($authkeys, $haresources, $ha_cf, $err, @init_services);
while (1) {
($authkeys, $err) = $config->authkeys();
last if (!defined($authkeys));
($haresources, $err, @init_services) = $config->haresources();
last if (!defined($haresources));
($ha_cf, $err) = $config->ha_cf();
last;
}
if (defined($err)) {
print STDERR "Cluster configuration error: $err\n";
exit 1;
}
my $ret = system("mkdir -p $HA_DIR");
if ($ret >> 8) {
print STDERR "Error: cannot create $HA_DIR\n";
exit 1;
}
# stop HA before changing config files
print "Stopping clustering...";
system("$HA_INIT stop >&/dev/null");
print " Done\n";
if (!open(CONF_AUTH, ">$HA_DIR/authkeys")) {
print STDERR "Error: cannot create $HA_DIR/authkeys\n";
exit 1;
}
if (!open(CONF_RES, ">$HA_DIR/haresources")) {
print STDERR "Error: cannot create $HA_DIR/haresources\n";
exit 1;
}
if (!open(CONF_CF, ">$HA_DIR/ha.cf")) {
print STDERR "Error: cannot create $HA_DIR/ha.cf\n";
exit 1;
}
print CONF_AUTH $authkeys;
print CONF_RES $haresources;
print CONF_CF $ha_cf;
close CONF_AUTH;
close CONF_RES;
close CONF_CF;
if (!chmod(0600, "$HA_DIR/authkeys")) {
print STDERR "Error: cannot change $HA_DIR/authkeys permissions\n";
exit 1;
}
$config->del_watchlink_exclude();
$config->add_watchlink_exclude();
# stop each service in case it is already started
foreach (@init_services) {
system("$SERVICE_DIR/$_ stop");
}
print "Starting clustering...";
system("$HA_INIT start >&/dev/null");
if ($? >> 8) {
print "\nError: Clustering failed to start.\n";
print "Please make sure all clustering interfaces are functional\n";
print "and retry the commit.\n";
exit 1;
}
print " Done\n";
exit 0;
|