LVS
lvs-users
Google
 
Web LinuxVirtualServer.org

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

To: Roberto Nibali <ratz@xxxxxxxxxxxx>
Subject: Re: At Startup, I Get This: sed: -e expression #1, char 1:?unknown?command: `%'
Cc: "LinuxVirtualServer.org users mailing list." <lvs-users@xxxxxxxxxxxxxxxxxxxxxx>
Cc: Robinson@xxxxxxxxxxxx
From: Horms <horms@xxxxxxxxxxxx>
Date: Thu, 6 Jul 2006 09:40:44 +0900
On Wed, Jul 05, 2006 at 01:03:57PM +0200, Roberto Nibali wrote:
> Hello Horms,
> 
> Usual nitpicking :).

Thanks mate, updated with your two changes is below.

-- 
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 synchronisation 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, 
+                                       "sync_daemon 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>