Skip to content

Instantly share code, notes, and snippets.

@tsunokawa
Created July 3, 2013 06:29
Show Gist options
  • Save tsunokawa/5915851 to your computer and use it in GitHub Desktop.
Save tsunokawa/5915851 to your computer and use it in GitHub Desktop.
LVS Memcached Check Command Script
#!/usr/bin/env perl
use strict;
use warnings;
## yum install perl-Cache-Memcached.noarch perl-String-Random.noarch
use Cache::Memcached;
use String::Random;
## HOST名とポート番号を受取る
my $vhost = $ARGV[0];
my $vport = $ARGV[1];
my $host = $ARGV[2];
my $port = $ARGV[3];
## キー、値、有効期限を設定
# キーをランダムに発行する(同じキーだと同じサーバーにしかsetされないので)
my $key = String::Random->new->randregex('lvshealthcheck[A-Za-z0-9]{5}');
my $value = "ok";
my $expire = "3";
## キー、値、有効期限をadd
my $memcached = Cache::Memcached->new({ servers => [ "$host:$port" ] });
## 値を上記で発行したキーで保存
$memcached->add($key,$value,$expire);
## オブジェクトをキャッシュから取得
my $cached = $memcached->get($key);
## valueがokかどうか判定
if ($cached ne "ok") {
exit(1);
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment