Conohaのオブジェクトストレージを使ってみた(REST API Ver)


オブジェクトストレージリリース記念モニター募集キャンペーン に応募してみたところ運よく当選できたので、REST APIで使ってみました。

コードは最近良く書く、Node.jsです。httpリクエストには、requestを使っています。
その他、asyncや、ユーティリティとして、lodashを入れています。

基本は、ConohaのAPIドキュメント通りだけど、いろいろハマりましたw
必要な情報は、管理画面で取得してください。

いろいろとできることのサンプルコードということで、エラー処理とかなんにもしていないので、あしからず。。。m(_ _)m (処理フローも確認だけだったので、warterfallですし。。。)

まずは、トークンの取得。(ちょっと雑ですがサンプルということで。。。)

var _ = require('lodash');
var httpRequest = require('request');

var tenantName = 'テナント番号';
var tenantId = 'テナントID';
var username = 'テナント番号';
var password = 'パスワード';

var api_url = 'https://ident-r1nd1001.cnode.jp';
var uri = '';

var object_storage_endpoint = 'https://objectstore-r1nd1001.cnode.jp/v1/エンドポイント';

var token = '';
var token_expire = '';

var params = {
    "url": api_url+'/v2.0/tokens',
    "headers": {
        "Accept": 'application/json'
    },
    "form": JSON.stringify({
        "auth": {
            "tenantName": tenantName,
            "passwordCredentials": {
                "username": username,
                "password": password
            }
        }
    })

};

// tokenを取得して、アカウント情報を取得

httpRequest.post(params, function(err, result, body){
    if(_.isString(body)){
        var res = JSON.parse(body);
    }else{
        var res = body;
    }

    console.log(res.body);

    token = res.access.token.id;
    token_expire = res.access.token.expires;
    console.log('token: ' + token);
    console.log('expire: ' + token_expire);

});

console.logの結果はこんな感じ。。。
(bodyは空なんですねっと)

undefined
token:  xxxxxxxxxxxxx(トークン情報)
expire: 2014-11-04T17:33:20Z

さて、これでトークン取得できたので、いろいろできますね!!

次は、コンテナ作成。(サンプルなので、わざと、アクセス情報毎回ということで。。。)

var _ = require('lodash');
var async = require('async');
var httpRequest = require('request');

var tenantName = 'テナント番号';
var tenantId = 'テナントID';
var username = 'テナント番号';
var password = 'パスワード';

var api_url = 'https://ident-r1nd1001.cnode.jp';
var uri = '';

var object_storage_endpoint = 'https://objectstore-r1nd1001.cnode.jp/v1/エンドポイント';

var token = '';
var token_expire = '';

var params = {
    "url": api_url+'/v2.0/tokens',
    "headers": {
        "Accept": 'application/json'
    },
    "form": JSON.stringify({
        "auth": {
            "tenantName": tenantName,
            "passwordCredentials": {
                "username": username,
                "password": password
            }
        }
    })
};

async.waterfall([
 function(next){
     // tokenを取得
     httpRequest.post(params, function(err, result, body){
         console.log('token ----------------------');
         console.log(err);
         if(_.isString(body)){
             var res = JSON.parse(body);
         }else{
             var res = body;
         }

         console.log(result.statusCode);

         console.log(res.body);

         token = res.access.token.id;
         token_expire = res.access.token.expires;
         console.log('token: ' + token);
         console.log('expire: ' + token_expire);
         next(err, token);
     });
 },

 function(token, next){
     // オブジェクトストレージエンドポイントに接続
     uri = object_storage_endpoint;

     httpRequest.head({url: uri, headers:{'X-Auth-Token': token}}, function(err, result, body){
         console.log('connect ----------------------');

         console.log(err);
         console.log(result.statusCode);

         //console.log(result);
         //console.log(body);
         next(err, token);
     });
 },

 function(token, next){
     // コンテナを作成
     var container = '/test';

     uri = object_storage_endpoint + container;

     httpRequest.put({url: uri, headers:{'X-Auth-Token': token} }, function(err, result, body){
         console.log('container ----------------------');

         console.log(err);
         console.log(result.statusCode);
         console.log(result.headers);
         console.log(body);
         next(err, token);
     });
 }

], function (err, result){

});

これで、コンテナの作成ができます。

コンテナ作成のところを以下のようにかえると、コンテナ削除が可能です。

function(next){
     // コンテナを削除
     var container = '/test';

     uri = object_storage_endpoint + container;

     httpRequest.del({url: uri, headers:{'X-Auth-Token': token} }, function(err, result, body){
         console.log('container ----------------------');

         console.log(err);
         console.log(result.statusCode);
         console.log(result.headers);
         console.log(body);
         next(err);
     });
 }

では、ファイルのアップコード。(同様にコンテナ作成のところを変更)

function(next){
     // ファイルをアップロード
     var container = '/test';

     var filename = '/sample.jpg'

     var formData = {
         file: fs.createReadStream(__dirname + '/test.jpg')
     };

     uri = object_storage_endpoint + container + filename;


     fs.createReadStream(__dirname + '/test.jpg').pipe(
         httpRequest.put({url: uri, headers:{'X-Auth-Token': token}}, function(err, result, body){
             console.log('upload ----------------------');

             console.log(err);
             console.log(result.statusCode);
             console.log(result.headers);
             console.log(body);
             next(err);
         })
     );

 }

アップロードしたファイル(オブジェクト)を指定時間後削除

function(next){
     // ファイルアップロード30秒後に削除
     var container = '/test';

     var filename = '/sample1.jpg'

     var formData = {
         file: fs.createReadStream(__dirname + '/test.jpg')
     };

     uri = object_storage_endpoint + container + filename;

     /*
      X-Delete-After: オブジェクトが削除されるまでの秒数。内部的にはX-Delete-Atへ日時を設定します。
      X-Delete-At: オブジェクトの削除予約日時。UNIX Epoch timestamp形式で設定します。
      */

     fs.createReadStream(__dirname + '/test1.jpg').pipe(
         httpRequest.put({url: uri, headers:{'X-Auth-Token': token, 'X-Delete-After': 30}}, function(err, result, body){
             console.log('upload ----------------------');

             console.log(err);
             console.log(result.statusCode);
             console.log(result.headers);
             console.log(body);
             next(err);
         })
     );

 }

アップしたファイル(オブジェクト)sample1.jpgとして取得する。

function(next){
     var container = '/test';

     var filename = '/sample1.jpg'

     var formData = {
         file: fs.createReadStream(__dirname + '/test.jpg')
     };

     uri = object_storage_endpoint + container + filename;

     httpRequest.get({url: uri, headers:{'X-Auth-Token': token}}, function(err, result, body){
         console.log('download ----------------------');

         console.log(err);
         console.log(result.statusCode);
         console.log(result.headers);
         console.log(body);
         next(err);
     });

 }

オブジェクトストレージの情報を取得するには、headでアクセス。

function(next){
     var container = '/test';

     var filename = '/sample1.jpg'

     var formData = {
         file: fs.createReadStream(__dirname + '/test.jpg')
     };

     uri = object_storage_endpoint + container + filename;

     httpRequest.head({url: uri, headers:{'X-Auth-Token': token}}, function(err, result, body){
         console.log('infomation ----------------------');

         console.log(err);
         console.log(result.statusCode);
         console.log(result.headers);
         console.log(body);
         next(err);
     });

 }

こんな感じで、ひと通りの操作はできたかなーっと。。。

まぁ、S3って感じですよね。。。w
回線費用無視できるので、もっと気軽に使えるのがかなり大きいですね!!

S3みたいに、OpenStack SwiftでPre-signed URLってswiftでできないんでしょうか。。。
(どなたかご存知であれば、ご教授下さい)

あと、REST APIとpkgcloudどっちがいいのか?(というか、メリット・デメリットも)わからないので、こちらも、知りたいなーとか思いながら、次の宿題。

pkgcloudについては、Node.jsでは、すでにお調べて頂いてる方がいらっしゃいます。
Conohaのオブジェクトストレージモニターに当選したので、Nodeで使ってみた

とりあえず、いろいろやっていこうと思います!!ありがとう!!Conohaさん!!

github製テキストエディタ atomのrpmパッケージを作成する。

ソースコンパイルだといろいろ面倒なので、以下で対応。

vim /root/rpmbuild/SPECS/atom.spec

Name:    atom
Summary: A hackable text editor for the 21st century.
Version: 0.126.0
Release: 1%{?dist}

Group:   Development/Editors
License: MIT
URL:     https://atom.io/

Source0: https://github.com/atom/atom/archive/v%{version}.tar.gz

# We also require node and npm to be on PATH, but we're relying on the user to
# supply their own. This is because the node-gyp build in Fedora's repositories
# is currently incompatible.
#
# This build has been confirmed to run flawlessly on NodeJS 0.10.28 installed
# via NVM. node-gyp can fail to build if your system has the gyp RPM installed,
# so remove that first.
BuildRequires: gcc-c++ libgnome-keyring-devel

BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

# Don't try to extract debuginfo from built packages
%global debug_package %{nil}
%global desktop_file  /opt/atom/share/applications/Atom.desktop

# Attempts to guess dependencies will likely also fail
AutoReqProv: no


%description
    Atom is a desktop application based on web technologies. Like other desktop
    apps, it has its own icon in the dock, native menus and dialogs, and full
    access to the file system.

    Open the dev tools, however, and Atom's web-based core shines through.
    Whether you're tweaking the look of Atom's interface with CSS or adding
    major features with HTML and JavaScript, it's never been easier to take
    control of your editor.


%prep
%setup -q


%build
# Set the build directory as per grunt.option('build-dir') in Gruntfile.coffee.
# This prevents Atom from being built somewhere in /tmp.
script/build --build-dir=$PWD/build-rpm


%install
# The install task honours the INSTALL_PREFIX environment variable, so specify
# it for easier packaging.
export INSTALL_PREFIX=%{buildroot}/opt/atom

# -d switch enables debugging output, -v enables verbose output
script/grunt -dv --build-dir=$PWD/build-rpm install

# Handle the desktop file (launcher)
sed -i "s@%{buildroot}@@g" %{buildroot}%{desktop_file}
mkdir -p %{buildroot}%{_datarootdir}/applications
ln -sf %{desktop_file} %{buildroot}%{_datarootdir}/applications/atom.desktop

# Link the binaries
mkdir -p %{buildroot}%{_bindir}
for binary in atom apm; do
    ln -sf /opt/atom/bin/$binary %{buildroot}%{_bindir}/$binary
done


%clean
rm -rf %{buildroot}


%post
xdg-desktop-menu forceupdate


%postun
xdg-desktop-menu forceupdate


%files
%defattr(-, root, root, -)
                           /opt/atom
                           %{_bindir}/*
                           %{_datarootdir}/applications/*

fedora20で npmをパッケージでインストールしていると、npmは1,3でコンパイルできません。

npm は、以下から取得しました。(野良パッケージが嫌なヒトは、どうしたらいいんだろう。。。)
http://rpm.pbone.net/index.php3/stat/4/idpl/26924811/dir/fedora_20/com/npm1.4-1.4.16-1.fc20.noarch.rpm.html

yum remove npm

yum localinstall -y npm1.4-1.4.16-1.fc20.noarch.rpm
yum install -y libgnome-keyring-devel
yum install -y gcc-c++

されて、ソースは、githubからダウンロードして、バージョンをSPECで併せて変更下さい。

rpmbuild -ba atom.spec

これで、今後のバージョンアップも追随が楽になるかな?

github製テキストエディタ atom (atom.io)を Linux (Fedora)で使う (おまけWindows)

githubテキストエディタatom(atom.io)さんがOSSになってリリースされてましたねー。
でも、 https://atom.io/ 上には、Macのビルドしか無いじゃん!!ってなるんですが、OSSになってから、各OSでのビルドがリリースされたり、ビルド方法が出てきました。

メイン開発環境は、Linux(Korora 20 Fedoraベースなので、ここで使いたいなーっと。(GUIKDEだったりします)

そのメモ。(尚この記事は、インフラ構築中の待ち時間の間に、気分転換に作業した内容となりますw)
こういうやり方の方がいいよ!!っていうのあったらご指摘、ご教授下さいませ!!

Linuxのビルド方法は、以下に記載されています。

https://github.com/atom/atom/blob/master/docs/build-instructions/linux.md

まぁ、これだけじゃ罠があるのですが。。。

1. 必要な依存モジュールをインストール

yum -y install node npm libgnome-keyring-devel

2. korora linuxは標準でgoogle chrome入れれるんですが yumのrepoが必要です。
(下記はkororaのrepoの内容)

vim /etc/yum.repos.d/google-chrome.repo

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1

3. npmをアップグレードする必要があるので、その対応(Fedoraは1.3.6で、atomは1.4が必要)

cd ~
npm install npm

# ローカルnpmのbin PATHの設定
export PATH="$HOME/node_modules/.bin:$PATH"

# インストールされたnpmのバージョン確認
npm --version
# 1.4.10

4. パッケージのgypをアンインストールする ( issue #2029
これに気づくのに時間かかりました。

yum -y remove gyp

5. atomのコードをcloneしてbuildする。

git clone https://github.com/atom/atom
cd atom

./script/build
||< 

実行すると、以下のログがズラズラと表示されます。

>|sh|
npm WARN package.json github-url-from-git@1.1.1 No repository field.

Installing modules &#10003;
Installing atom-dark-syntax@0.15.0 &#10003;                                                                                           
Installing atom-dark-ui@0.26.0 &#10003;                                                                                               
Installing atom-light-syntax@0.17.0 &#10003;                                                                                          
Installing atom-light-ui@0.24.0 &#10003;                                                                                              
Installing base16-tomorrow-dark-theme@0.15.0 &#10003;                                                                                 
Installing solarized-dark-syntax@0.14.0 &#10003;                                                                                      
Installing solarized-light-syntax@0.7.0 &#10003;                                                                                      
Installing archive-view@0.30.0 &#10003;                                                                                               
Installing autocomplete@0.27.0 &#10003;                                                                                               
Installing autoflow@0.16.0 &#10003;                                                                                                   
Installing autosave@0.13.0 &#10003;                                                                                                   
Installing background-tips@0.13.0 &#10003;                                                                                            
Installing bookmarks@0.22.0 &#10003;                                                                                                  
Installing bracket-matcher@0.33.0 &#10003;                                                                                            
Installing command-palette@0.21.0 &#10003;                                                                                            
Installing deprecation-cop@0.5.0 &#10003;                                                                                             
Installing dev-live-reload@0.30.0 &#10003;                                                                                            
Installing exception-reporting@0.17.0 &#10003;                                                                                        
Installing feedback@0.33.0 &#10003;                                                                                                   
Installing find-and-replace@0.101.0 &#10003;                                                                                          
Installing fuzzy-finder@0.50.0 &#10003;                                                                                               
Installing git-diff@0.28.0 &#10003;                                                                                                   
Installing go-to-line@0.19.0 &#10003;                                                                                                 
Installing grammar-selector@0.26.0 &#10003;                                                                                           
Installing image-view@0.33.0 &#10003;                                                                                                 
Installing keybinding-resolver@0.17.0 &#10003;                                                                                        
Installing link@0.22.0 &#10003;                                                                                                       
Installing markdown-preview@0.69.0 &#10003;                                                                                           
Installing metrics@0.32.0 &#10003;                                                                                                    
Installing open-on-github@0.28.0 &#10003;                                                                                             
Installing package-generator@0.30.0 &#10003;                                                                                          
Installing release-notes@0.29.0 &#10003;                                                                                              
Installing settings-view@0.114.0 &#10003;                                                                                             
Installing snippets@0.43.0 &#10003;                                                                                                   
Installing spell-check@0.35.0 &#10003;                                                                                                
Installing status-bar@0.40.0 &#10003;                                                                                                 
Installing styleguide@0.29.0 &#10003;                                                                                                 
Installing symbols-view@0.51.0 &#10003;                                                                                               
Installing tabs@0.39.0 &#10003;                                                                                                       
Installing timecop@0.18.0 &#10003;                                                                                                    
Installing tree-view@0.92.0 &#10003;                                                                                                  
Installing update-package-dependencies@0.6.0 &#10003;                                                                                 
Installing welcome@0.13.0 &#10003;                                                                                                    
Installing whitespace@0.22.0 &#10003;                                                                                                 
Installing wrap-guide@0.18.0 &#10003;                                                                                                 
Installing language-c@0.15.0 &#10003;                                                                                                 
Installing language-coffee-script@0.22.0 &#10003;                                                                                     
Installing language-css@0.16.0 &#10003;                                                                                               
Installing language-gfm@0.34.0 &#10003;                                                                                               
Installing language-git@0.9.0 &#10003;                                                                                                
Installing language-go@0.11.0 &#10003;                                                                                                
Installing language-html@0.19.0 &#10003;                                                                                              
Installing language-hyperlink@0.9.0 &#10003;                                                                                          
Installing language-java@0.10.0 &#10003;                                                                                              
Installing language-javascript@0.25.0 &#10003;                                                                                        
Installing language-json@0.8.0 &#10003;                                                                                               
Installing language-less@0.9.0 &#10003;                                                                                               
Installing language-make@0.10.0 &#10003;                                                                                              
Installing language-objective-c@0.11.0 &#10003;                                                                                       
Installing language-perl@0.8.0 &#10003;
Installing language-php@0.14.0 &#10003;
Installing language-property-list@0.7.0 &#10003;
Installing language-python@0.15.0 &#10003;
Installing language-ruby@0.23.0 &#10003;
Installing language-ruby-on-rails@0.12.0 &#10003;
Installing language-sass@0.10.0 &#10003;
Installing language-shellscript@0.8.0 &#10003;
Installing language-source@0.7.0 &#10003;
Installing language-sql@0.8.0 &#10003;
Installing language-text@0.6.0 &#10003;
Installing language-todo@0.10.0 &#10003;
Installing language-toml@0.12.0 &#10003;
Installing language-xml@0.12.0 &#10003;
Installing language-yaml@0.6.0 &#10003;
Deduping modules &#10003;
Running "download-atom-shell" task


Running "build" task

Running "coffee:glob_to_multiple" (coffee) task

Running "prebuild-less:src" (prebuild-less) task

Running "cson:glob_to_multiple" (cson) task
>> 153 files compiled to JSON.

Running "peg:glob_to_multiple" (peg) task

Running "generate-license:save" (generate-license) task

Running "set-version" task
Done, without errors.

>> 153 files compiled to JSON.

Running "peg:glob_to_multiple" (peg) task

Running "generate-license:save" (generate-license) task

Running "set-version" task
Done, without errors.

6. makeされたatomバイナリに実行権限を付与

chmod +x /tmp/atom-build/Atom/atom

7. アンインストールしたnode-gypを再度インストールするしておく。(今後別のモジュール入れるのに忘れそうなので。。。)

yum -y install node-gyp

8. atomエディタの起動確認

LD_LIBRARY_PATH=/opt/google/chrome ./atom.sh

(∩´∀`)∩ワーイ 起動したってなりますw(日本語OKでした。かなりデカイ)

9. atomをアプリケーションフォルダに移動
/home/ユーザー名/Applications っていうフォルダに自分で導入したアプリを管理しているので、こっちに移動します。

mkdir -p ~/Applications/atom/share

mv /tmp/atom-build/Atom ~/Applications/atom/share/atom

cp resources/atom.png /home/dai_yamashita/Applications/atom/share/atom/resources/

cp atom.sh ~/Applications/atom/share

# 起動確認
LD_LIBRARY_PATH=/opt/google/chrome ~/Applications/atom/share/atom.sh

これで、おわりー!!

面倒なんで、起動シェルを書いてます。(起動確認コマンドと一緒)

#/bin/sh
LD_LIBRARY_PATH=/opt/google/chrome ~/Applications/atom/share/atom.sh

ちなみに、いろいろ自分で試行錯誤してたんですが、やり方はほとんど同じものでまとめて頂いているのがあったので、
そちらを参照頂く方が良いかと。。。w

https://gist.github.com/mojavelinux/225d01e621f467db1c75

こちらだと、/usr/share/applications/atom.desktop に書けば起動メニューから起動できるよ的なことを書いていますね。
(よくわかっていない)

vim /usr/share/applications/atom.desktop

[Desktop Entry]
Type=Application
Name=Atom
Comment=AEHOOOO
Icon=/opt/Atom/resources/app/resources/atom.png
Exec=/opt/Atom/atom.sh
Terminal=false
Categories=Development;

なんかわからないので、上記は実施していません。気になったので、ちょっとググってみたら、こんなのものあった。
http://pastebin.com/19e3y7c1

[Desktop Entry]
Name=Atom
Comment=Atom is a hackable text editor for the 21st century
Exec=atom %U
Icon=/home/cjgomes/.local/share/icons/atom.svg
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Utility;TextEditor;

X-Ayatana-Desktop-Shortcuts=pncsaNew;eosbrNew;WindowNew;Root

[pncsaNew Shortcut Group]
Name=Projeto pncsawp
Exec=/usr/local/share/atom/atom --executed-from=/home/cjgomes/Documentos/github/pncsawp/ %U
TargetEnvironment=Unity

[eosbrNew Shortcut Group]
Name=Projeto eosbr
Exec=/usr/local/share/atom/atom --executed-from=/home/cjgomes/Documentos/github/eosbrwp/ %U
TargetEnvironment=Unity

[WindowNew Shortcut Group]
Name=Nova Janela
Exec=/usr/local/share/atom/atom %U
TargetEnvironment=Unity

[Root Shortcut Group]
Name=Nova Janela como _Administrator
Exec=gksu atom
TargetEnvironment=Unity

おまけ
Windows版のバイナリは公開されているので、以下からダウンロードできます。

http://blog.someguy123.com/atom-builds-for-windows/

それでは、皆さんよい、atom ライフを!!

Node.jsでS3内のデータをダウンロードするのではできたけど、次の処理に繋げれない。。。

Node.jsで、S3内のデータをダウンロードする処理を書いた。
実際は、次のステップのことをやりたいんだけど、stream関連が理解できていないなぁーっと痛感する。。。
これを、FTP接続して、他のサーバにアップロードしたいってのが、やりたいことですが。。。

ダウンロードしたファイルをreadablestreamに読み込んで、pipeして、アップするとか、
そもそも、メモリにwritablestreamでかいて、それをアップロードするとか、
いろいろわかっていないので、どなたかご教授頂けますと幸いです。m(_ _)m

aws-sdkは導入済みで、以下を参照して、事前準備済みが前提です。
http://aws.amazon.com/jp/sdkfornodejs/

コードはこんな感じ。

var AWS = require('aws-sdk');
var _ = require('lodash');
var fs = require('fs');
var path = require('path');

AWS.config.loadFromPath('./config.json');
var s3 = new AWS.S3();

// バケット内のobjectを取得(bucket名は各自のbucket名を設定してください)
s3.listObjects({Bucket: 'your_bucket_name'}, function (err, data) {
  if(_.isNull(err)){
      _.forEach(data.Contents, function(object){
          if(object.Size > 0){
              //console.log(object);
              //console.log(path.dirname(object.Key));
              //console.log(path.basename(object.Key));

              var ws = fs.createWriteStream(path.basename(object.Key), {flags: 'a'});

              s3.getObject({Bucket: 'your_bucket_name', Key:object.Key}, function(err, result){
                ws.write(result.Body);
              });
          }
      });
  }
});

Node.jsでIP Messengerにメッセージを送ってみた。

みんな大好きIPMSG!! いろいろあってストレス溜まっていたので、ちょっとした気分転換に、Node.jsでメッセージを送信してみました。

今回のサンプルを動かすにあたっては、事前に以下のnpmをインストールしておいて下さい。

npm install sprintf
npm install jconv
// ipmsg.js

var dgram = require('dgram');
var sprintf = require('sprintf').sprintf;
var jconv = require('jconv');

var udp = dgram.createSocket("udp4");

var version = 0x0001;
//var IPMSG_SENDMSG = 0x00000020;
var command = 0x00000020;

var user = 'dai_yamashita';
var host = 'myhost';

function makemsg(message){
    return jconv.convert(sprintf("%d:%d:%s:%s:%d:%s", version, Math.floor(Math.random() * 1000 + 1), user, host, command, message), 'UTF8', 'SJIS');
}


var msg = "ヽ(=´▽`=)ノ";

udp.send(makemsg(msg), 0, makemsg(msg).length, 2425, "192.168.xxx.xxx", function(err, bytes) {
    // console.log(err);
    // console.log(bytes);
    udp.close();
});

これで、

node ipmsg.js

とかすると、IPメッセンジャー さんに、udp.sendで設定した送信先

ヽ(=´▽`=)ノ

というのが、届いているかと思います。

もう少し、いろいろすると、整えると、gruntとかでtask完了後に、ipmsgにメッセージを飛ばすとか出来るので、もうちょっと暇を見て、弄っていきたいと思います。

あと、LinuxでいいIPMSGクライアントあれば教えてください。。m(_ _)m

Varnishで443ポートもリッスンする

なんだかんだで、ちょろちょろとVarnishさんを触っています。
VarnishさんでSSL関連が触れないのは、皆さん周知の事実だと思いますが、
なにもしなくていいから、バックエンドにそのまま流してくれと、(バックエンド側でSSL紐解けば)というのをやってみたかったので、試した所、
翌々考えたら、80ポートしかリッスンさせてなかったので(気づくのにちょっと時間かかったw)未来の自分への備忘録。
(タダの恥さらしの記録ですねー( ゚ ρ ゚ ))

■環境
Scientific Linux

■Varnish
3.0.4 (rpmパッケージを作って、導入しています。理由は、また次の機会にでも。。。)

yum等で導入した場合、パッケージに入っているinitscriptは、/etc/sysconfig/varnish の内容を読んでいることが確認できます。
んで、最初の状況がこれ。リッスンポートを80に変えただけの標準ですねー。

変えたとこ

#VARNISH_LISTEN_PORT=6081
VARNISH_LISTEN_PORT=80

全部

# Configuration file for varnish
#
# /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this
# shell script fragment.
#

# Maximum number of open files (for ulimit -n)
NFILES=131072

# Locked shared memory (for ulimit -l)
# Default log size is 82MB + header
MEMLOCK=82000

# Maximum number of threads (for ulimit -u)
NPROCS="unlimited"

# Maximum size of corefile (for ulimit -c). Default in Fedora is 0
# DAEMON_COREFILE_LIMIT="unlimited"

# Set this to 1 to make init script reload try to switch vcl without restart.
# To make this work, you need to set the following variables
# explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,
# VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE, or in short,
# use Alternative 3, Advanced configuration, below
RELOAD_VCL=1

# This file contains 4 alternatives, please use only one.

## Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# content server on localhost:8080.  Use a fixed-size cache file.
#
#DAEMON_OPTS="-a :6081 \
#             -T localhost:6082 \
#             -b localhost:8080 \
#             -u varnish -g varnish \
#             -s file,/var/lib/varnish/varnish_storage.bin,1G"


## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request.  Use a
# fixed-size cache file.
#
#DAEMON_OPTS="-a :6081 \
#             -T localhost:6082 \
#             -f /etc/varnish/default.vcl \
#             -u varnish -g varnish \
#             -S /etc/varnish/secret \
#             -s file,/var/lib/varnish/varnish_storage.bin,1G"


## Alternative 3, Advanced configuration
#
# See varnishd(1) for more information.
#
# # Main configuration file. You probably want to change it :)
VARNISH_VCL_CONF=/etc/varnish/default.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
#VARNISH_LISTEN_PORT=6081
VARNISH_LISTEN_PORT=80

#
# # Telnet admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
#
# # Shared secret file for admin interface
VARNISH_SECRET_FILE=/etc/varnish/secret
#
# # The minimum number of worker threads to start
VARNISH_MIN_THREADS=50
#
# # The Maximum number of worker threads to start
VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
#
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
VARNISH_STORAGE_SIZE=1G
#
# # Backend storage specification
VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script.  If you add or remove options, make
# # sure you update this section, too.
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
             -f ${VARNISH_VCL_CONF} \
             -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
             -t ${VARNISH_TTL} \
             -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
             -u varnish -g varnish \
             -S ${VARNISH_SECRET_FILE} \
             -s ${VARNISH_STORAGE}"
#


## Alternative 4, Do It Yourself. See varnishd(1) for more information.
#
# DAEMON_OPTS=""

で、LISTENポートに追加したらいいんだろうなぁーっと思って、カンマで区切って443だとダメなんですねー。
-a オプションで、127.0.0.1:80とかで起動する必要がありますので。。。

なので、ダメなこなんで、

VARNISH_LISTEN_PORT=:80,:443

って書いちゃったんですねー。。。 configtestしても、こんなとこチェックしてくれるわけもなく。。。
起動方法なので、restartをかけたところ、エラーですねー。。。

なぜかというと。。。重要なのは、DAEMONS_OPTが起動オプションですが、

DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \

に記載されている${VARNISH_LISTEN_PORT}の前に「:」あるじゃん!!っていうのがあるからです。。。orz(はい、アラート鳴らしてしまいました。。。)
このまま、DAEMON_OPTS書きなおさないなら、以下のように書く必要があります。

VARNISH_LISTEN_PORT=80,:443

でも、どうせなら、標準で、

VARNISH_LISTEN_PORT=:80,:443

して、

DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}${VARNISH_LISTEN_PORT} \

このほうが、綺麗じゃね??とか思った次第であります。

アラート鳴らしてごめんなさい。。。m(_ _)m

ちなみに、443ポートはpipeをさせていますが、途中で接続が切られています。
(バックエンド側の問題なのか、切り分けができていません。テストに使ったバックエンドがTeraStationというw)

varnishlog眺めてると、

varnishlog 
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477969 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477972 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477975 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477978 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477981 1.0
   14 SessionOpen  c xxx.xxx.xxx.xxx 62894 :443
   14 Debug        c herding
   14 SessionClose c timeout
   14 StatSess     c xxx.xxx.xxx.xxx 62894 0 1 0 0 0 0 0 0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477984 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477987 1.0
   14 SessionOpen  c xxx.xxx.xxx.xxx 63009 :443
   14 Debug        c herding
   14 SessionClose c timeout
   14 StatSess     c xxx.xxx.xxx.xxx 63009 0 1 0 0 0 0 0 0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477990 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477993 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477996 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1378477999 1.0

何か、良い切り分け方法や、これじゃできてないよ、みたいなのがあれば、ご教授下さいませ m(_ _)m

Windows8.1でOpenVPNが動かなかったのを動かす方法。

Windows8.1 Previewにアップデートしたら、OpenVPNが動かなくなりました。。。orz
これ結構死活問題だったので、動くようにする方法。

以下参照。
https://airvpn.org/topic/9645-openvpn-tap-windows-81-adapter-problem/

C:\Program Files\TAP-Windows\bin\devcon.exe

を右クリックでプロパティで「互換性」タブ -「互換モードでこのプログラムを実行する」- 「Windows7

を設定すると、動くようになります。(*´▽`*)