LVS
lvs-users
Google
 
Web LinuxVirtualServer.org

Re: At Startup, I Get This: sed: -e expression #1, char 1:?unknown?comma

To: "LinuxVirtualServer.org users mailing list." <lvs-users@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: At Startup, I Get This: sed: -e expression #1, char 1:?unknown?command: `%'
Cc: Robinson@xxxxxxxxxxxxxxxxx
From: Horms <horms@xxxxxxxxxxxx>
Date: Wed, 5 Jul 2006 18:47:55 +0900 (JST)
On Tue,  4 Jul 2006 11:00:15 +0900 (JST), Horms wrote:
> Robinson, Eric wrote:
>> I'm using CentOS 4.3 (kernel 2.6.9) so I can just remove the
>> LVSSyncDaemonSwap script from haresources? 
> 
> You should remove LVSSyncDaemonSwap from haresource and make sure
> that both the IPVS sync master and backup are started at boot.
> That is, the following needs to run sometime at boot:
> 
> ipvsadm --start-daemon master
> ipvsadm --start-daemon slave
> 
> This should probably be integrated into ldirectord somehow.
> Patches welcome :)

I wrote up a patch to do this, it adds the sync_daemon option to
ldirectord.cf. Though I am not sure if it should be added to ldirectord,
as it may confuse people who run ldirectord out of heartbeat's
haresources file.

I think that instead/as well I will try and get sync daemon startup into
the ipvsadm init script.

-- 
Horms                                           
  H: http://www.vergenet.net/~horms/
  W: http://www.valinux.co.jp/en/


Index: ldirectord
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/ldirectord/ldirectord,v
retrieving revision 1.138
diff -u -r1.138 ldirectord
--- a/ldirectord/ldirectord     5 Jul 2006 03:49:45 -0000       1.138
+++ b/ldirectord/ldirectord     5 Jul 2006 09:16:16 -0000
@@ -186,6 +186,23 @@
 for details.
 
 
+B<sync_daemon = >[B<off>|B<on>|B<master>|B<backup>]
+
+Start the LVS synchronsation daemon. off will not start the daemon.
+on starts both the master and backup daemons. master will start only
+the master daemon. backup will start only the backup daemon.
+
+If a daemon is configured to be started by ldirectord, it will
+also be stopped by ldirectord when ldirectord exits. If ldirectord
+is being run as a resource for heartbeat, and thus started and stoped
+on failover, then it probably is best to set this parameter to off
+and start and stop the synchronisation daemons by other means.
+
+Note also that older kernels (<2.4.27?) can only run one daemon at a time.
+
+The default is off
+
+
 B<quiescent = >[B<yes>|B<no>]
 
 If I<yes>, then when real or failback servers are determined
@@ -395,6 +414,7 @@
            $RUNPID
            $CHECKTIMEOUT
            $QUIESCENT
+           $SYNC_DAEMON
 
            $CALLBACK
            $CFGNAME
@@ -1027,6 +1047,11 @@
                        $LD_INSTANCE{$1} = 1;
                } elsif ($_ =~ /^supervised/) {
                        $SUPERVISED = 1;
+               } elsif ($_ =~ /^sync_daemon\s*=\s*(.*)/) {
+                       ($1 eq "on" || $1 eq "off" || $1 eq "master" || $1 eq 
"backup")
+                           or &config_error($line, 
+                                       "quiescent must be 'on', 'off', 
'master' or 'backup'");
+                       $SYNC_DAEMON = $1;
                } elsif ($_ =~ /^quiescent\s*=\s*(.*)/) {
                        ($1 eq "yes" || $1 eq "no")
                            or &config_error($line, 
@@ -1422,6 +1447,7 @@
 
 sub ld_setup
 {
+       ld_sync_start($SYNC_DAEMON);
        for my $v (@VIRTUAL) {
                if ($$v{protocol} eq "tcp") {
                        $$v{proto} = "-t";
@@ -1683,6 +1709,8 @@
                &system_wrapper("$IPVSADM -D $$v{proto} " .  &get_virtual($v));
                &ld_log("Removed virtual server (stop): " .  &get_virtual($v));
        }
+
+       ld_sync_stop($SYNC_DAEMON);
 }
 
 
@@ -3602,3 +3630,103 @@
 {
        return ld_find_cmd_path($_[0], $ENV{'PATH'}, $_[1]);
 }
+
+# ld_sync_get_status
+# Check the status of the ipvs sync daemon
+# pre: type: "backup" or "master"
+# return: PID of running sync daemon
+#         undef otherwise
+sub ld_sync_get_status
+{
+       my ($type) = (@_);
+       my $status = 0;
+
+       open PS, "ps ax|" or return;
+
+       while(<PS>) {
+               m/ \[ipvs[ _]sync$type\]$/ or next;
+               s/ *//;
+               s/ .*$//;
+               $status = $_;
+               last;
+       }
+
+       close PS;
+       return $status;
+}
+
+# __ld_sync_stop
+# Run the ipvs sync daemon if it is not already running, else do nothing
+# pre: type: "backup" or "master"
+# return: none
+sub __ld_sync_stop
+{
+       my ($type) = (@_);
+       my $result;
+
+       if (not ld_sync_get_status($type)) {
+               $result = "skipped (not running)";
+       }
+       elsif (system_wrapper("ipvsadm --stop-daemon $type") != 0) {
+               $result = "fail";
+       }
+       else {
+               $result = "ok";
+       }
+       ld_log("Stopping ipvs sync$type: $result");
+}
+
+# ld_sync_stop
+# Stop the ipvs sync daemons using __ld_sync_stop()
+# pre: type: "off", "on", "backup" or "master"
+# return: none
+sub ld_sync_stop
+{
+       my ($type) = (@_);
+
+       if ($type eq "on" or $type eq "master") {
+               __ld_sync_stop("master");
+       }
+       if ($type eq "on" or $type eq "backup") {
+               __ld_sync_stop("backup");
+       }
+}
+
+# __ld_sync_start
+# Stop the ipvs sync daemon if it is running, else do nothing
+# pre: type: "backup" or "master"
+# return: none
+sub __ld_sync_start
+{
+       my ($type) = (@_);
+       my $result;
+
+       if (ld_sync_get_status($type)) {
+               $result = "skipped (already running)";
+       }
+       elsif (system_wrapper("ipvsadm --start-daemon $type") != 0) {
+               $result = "fail";
+       }
+       else {
+               $result = "ok";
+       }
+       ld_log("Starting ipvs sync$type: $result");
+}
+
+
+# ld_sync_start
+# Stop the ipvs sync daemons using __ld_sync_start()
+# pre: type: "off", "on", "backup" or "master"
+# return: none
+sub ld_sync_start
+{
+       my ($type) = (@_);
+
+       if ($type eq "on" or $type eq "master") {
+               __ld_sync_start("master");
+       }
+       if ($type eq "on" or $type eq "backup") {
+               __ld_sync_start("backup");
+       }
+}
+
Index: ldirectord.cf
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/ldirectord/ldirectord.cf,v
retrieving revision 1.26
diff -u -r1.26 ldirectord.cf
--- ldirectord.cf       5 Aug 2005 06:18:17 -0000       1.26
+++ ldirectord.cf       5 Jul 2006 09:16:17 -0000
@@ -16,6 +16,7 @@
 #logfile="/var/log/ldirectord.log"
 #logfile="local0"
 quiescent=yes
+sync_daemon=off
 
 # A sample virual with a fallback that will override the gobal setting
 virtual=192.168.6.240:80


<Prev in Thread] Current Thread [Next in Thread>