Created
July 3, 2013 06:29
-
-
Save tsunokawa/5915851 to your computer and use it in GitHub Desktop.
LVS Memcached Check Command Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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