summaryrefslogtreecommitdiff
path: root/scripts/vyatta-update-cluster.pl
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2007-12-17 14:46:33 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2007-12-17 14:46:33 -0800
commit41aac6942e89fa24b938ec188a0933e52acff623 (patch)
tree0a7a4046dd0bede6fd1a7fc8c8082a068cc6fbe3 /scripts/vyatta-update-cluster.pl
downloadvyatta-cluster-41aac6942e89fa24b938ec188a0933e52acff623.tar.gz
vyatta-cluster-41aac6942e89fa24b938ec188a0933e52acff623.zip
migrate clustering from fairfield to glendaleupstream
Diffstat (limited to 'scripts/vyatta-update-cluster.pl')
-rwxr-xr-xscripts/vyatta-update-cluster.pl78
1 files changed, 78 insertions, 0 deletions
diff --git a/scripts/vyatta-update-cluster.pl b/scripts/vyatta-update-cluster.pl
new file mode 100755
index 0000000..c90dcf8
--- /dev/null
+++ b/scripts/vyatta-update-cluster.pl
@@ -0,0 +1,78 @@
+#!/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");
+ exit 0;
+}
+
+open(OUT, ">>/tmp/cl.log") or exit 1;
+
+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;
+}
+
+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;
+}
+
+# stop each service in case it is already started
+foreach (@init_services) {
+ system("$SERVICE_DIR/$_ stop");
+}
+
+# restart clustering.
+# using "stop" + "start" ("restart" will cause a long wait).
+# (may need to change to "restart".)
+system("$HA_INIT stop");
+system("$HA_INIT start");
+
+close OUT;
+exit 0;
+