2012年6月16日土曜日

OpenShiftDIYの作り方


Started with DIY Applications on OpenShift
https://openshift.redhat.com/community/blogs/a-paas-that-runs-anything-http-getting-started-with-diy-applications-on-openshift
とりあえず機械翻訳そのまんま、徐々に直すかな。

In addition to supporting Perl, Ruby, PHP, Python, and Java EE6, the OpenShift environment supports the "Do it Yourself" or "DIY" application type.
PerlやRuby、PHP、Python、及びJava EE6のサポートに加え、OpenShift環境をサポートするのが、"DIY" または"Do it Yourself"アプリケーションタイプです。
Using this application type, you can run just about any program that speaks HTTP.
このアプリケーション·タイプを使用して、HTTPを話すすべてのプログラムについてだけ実行することができます。

How this works is remarkably straightforward.
これがどのように動作するかは、とても直接的です。
The OpenShift execution environment is a carefully secured Red Hat Enterprise Linux 6.2 on x64 systems.
OpenShift実行環境は、x64システム上で慎重に確保されたRed Hat Enterprise Linux6.2です。
Thus, OpenShift can run any binary that will run on RHEL 6.2 x64.
したがって、OpenShiftは、RHEL6.2 x64上で実行される任意のバイナリを実行することができます。

The way that OpenShift DIY interfaces your application to the outside world is that creates a HTTP proxy specified by the environment variables OPENSHIFT_INTERNAL_IP and OPENSHIFT_INTERNAL_PORT.
OpenShift DIY·インタフェース外の世界へは、アプリケーションが環境変数OPENSHIFT_INTERNAL_IPとOPENSHIFT_INTERNAL_PORTで指定されたHTTPプロキシを作成することであることをする方法。
All your application has to do is bind and listen on that address and port.
すべてのアプリケーションは、そのアドレスとポートをバインドしリッスンする必要があります。
HTTP requests will come into the OpenShift environment, which will proxy those requests to your application.
HTTPリクエストは、アプリケーションへのプロキシこれらの要求をれる、OpenShift環境に来る。
Your application will reply with HTTP responses, and the OpenShift environment will relay those responses back to your users.
アプリケーションは、HTTPレスポンスで応答し、OpenShift環境がユーザーに戻ってそれらの応答を中継します。

Your application will be executed by the .openshift/action_hooks/start script, and will be stopped by the .openshift/action_hooks/stop script.
アプリケーションが.openshift/ action_hooksによって実行/スクリプトを起動し、スクリプトを停止/.openshift/ action_hooksによって停止されますされます。

To learn more about how it works, follow along with as we construct a simple C application, and then run it as an OpenShift DIY.
それがどのように動作するかの詳細については、我々は単純なCアプリケーションを構築し、OpenShift DIYとしてそれを実行するようにと一緒に従ってください。
We will use the libmicrohttpd library so we dont have to write our own HTTP server.
我々は独自のHTTPサーバを書くために持っていけないので、我々はlibmicrohttpdライブラリを使用します。

Run the following commands at a shell prompt on your own Linux or MacOS machine.
独自のLinuxやMacOSのマシンのシェルプロンプトで次のコマンドを実行します。

svn checkout https: //gnunet.org/svn/libmicrohttpd/src-libmicrohttpd
cd src-libmicrohttpd
autoreconf -fi
mkdir ${HOME}/lib-libmicrohttpd
./configure --prefix=${HOME}/lib-libmicrohttpd make && make install
cd ${HOME}

Next, we download the binhello.c sample program.
次に、我々はbinhello.cサンプルプログラムをダウンロードしてください。

curl -NOL https ://raw.github.com/openshift/openshift-diy-binhello-demo/master/binhello.c

This was originally the "hellobrowser.c" from the libmicrohttpd examples, but has been modified to run in OpenShift, by looking for the OPENSHIFT_INTERNAL_IP and OPENSHIFT_INTERNAL_PORT environment variables, and then binding to and listening on that address and port.
これは、もともとlibmicrohttpdの例から "hellobrowser.c"でしたが、OPENSHIFT_INTERNAL_IPとOPENSHIFT_INTERNAL_PORT環境変数を探し、その後に結合し、そのアドレスとポートをリッスンすることによって、OpenShiftで実行するように変更されています。

Next, we compile the program. We will statically link the libmicrohttpd.a object instead of using the .so shared object libraries.
次に、我々はプログラムをコンパイルします。我々は静的ますので、共有オブジェクト·ライブラリを使用する代わりにlibmicrohttpd.aオブジェクトをリンクします。
We could instead include the shared object library files into our application, and then play with LD_PRELOAD, but that is more than we want to do for this demo.
我々は代わりに私たちのアプリケーションに共有オブジェクトライブラリファイルを含めることができますし、LD_PRELOADと遊ぶ、それは我々がこのデモのために何をしたい以上です。

gcc -o binhello binhello.c ${HOME}/lib-libmicrohttpd/lib/libmicrohttpd.a -L ${HOME}/lib-libmicrohttpd/include -pthread

If we want to skip that step, and avoid playing with the GCC compiler, we can instead download a precompiled binary:
私達はそのステップをスキップして、GCCコンパイラと一緒に遊んで回避したい場合は、代わりにコンパイル済みのバイナリをダウンロードすることができます。

curl -NOL https ://raw.github.com/openshift/openshift-diy-binhello-demo/master/binhello
chmod +x ./binhello

Next, we create the OpenShift application container.
次に、我々はOpenShiftアプリケーションコンテナを作成します。
We will name this application jamie, after one of the kings of Do It Yourself: Jamie Hyneman.
ジェイミーHyneman:我々はそれを自分の王の一人した後、このアプリケーションジェイミー名前を付けます。

rhc-create-app -a jamie -t diy-0.1

Next, we place our binary into the local git repo we just created.
次に、先ほど作成したローカルのgitリポジトリに我々のバイナリを配置します。

mkdir jamie/bin
mv binhello jamie/bin
cd jamie
git add bin/binhello

Next, we tell OpenShift how to run our program. We go into the .openshift/action-hooks directory
次に、我々はプログラムを実行する方法をOpenShift教えてください。我々は.openshift/アクションフックディレクトリに移動

cd .openshift/action_hooks

and replace the start script with the following text:
次のテキストで起動スクリプトを置き換えます。

#!/bin/bash
cd $OPENSHIFT_REPO_DIR/bin
nohup ./binhello >;${OPENSHIFT_LOG_DIR}/binhello.log 2>&1 &

We are redirecting the UNIX standard output and standard error to a file in the OpenShift logging directory, and using nohup to assure that the program properly runs in the background.
我々はディレクトリを記録しているOpenShiftでUNIX標準出力と標準エラーをファイルにリダイレクトしていて、プログラムがバックグラウンドできちんと動作することを保証するために、nohupを使っています。

Next, we replace the stop script with the following text:
次に、我々は停止スクリプトを以下のテキストと入れ替えます:

#!/bin/bash
kill `ps -ef | grep binhello | grep -v grep | awk '{ print $2 }'` >; /dev/null 2>&1
exit 0

We make sure those scripts are still executable.
我々は、それらのスクリプトがまだ実行可能なことを確認します。

chmod +x start stop

Now, we go back to the top directory of our application, commit it to git, and push it up to the OpenShift servers.
現在、我々はアプリケーションの一番上のディレクトリに戻って、それをクズに任せて、それをOpenShiftサーバーまで上げます。

cd ../..
git commit -a -m "install the binhello binary and start stop scripts"
git push

We can then browse to the application.
それから、我々はアプリケーションに閲覧することができます。
In my case, it will be http://jamie-matwood.rhcloud.com/.
私のケースでは、それはhttp://jamie-matwood.rhcloud.com/.です。
We should see a very simple Hello, World!
我々は、非常に単純なハローワールドを見なければなりません!

And that is all there is to it!
そして、つまり、そこのすべては、それにあります!

Using the DIY application type, you can do all sorts of crazy things.
DIYアプリケーション・タイプを使って、あなたはいろいろな狂ったことをすることができます。
Do you have a favorite scripting language that OpenShift does not yet support?
OpenShiftがまだサポートしない大好きなスクリプト言語が、あなたにはありますか?
Do you have a framework written in Smalltalk?
あなたは、フレームワークをSmalltalkで書いておきますか?
Do you have a HTTP server written in Fortran?
あなたは、HTTPサーバをFortranで記述しておきますか?
Do you have a control server for a model train?
あなたには、模型の電車のために制御サーバーがありますか?
With DIY, you can run it on OpenShift.
DIYで、あなたはOpenShiftの上でそれを走らせることができます。

We would like to extend a challenge:
挑戦を延長したいです:
If you do something useful, amazing, or crazy with the DIY application container, please contact us at openshift@redhat.com, or tell us on the OpenShift Forums or come to IRC at freenode.net #openshift. We want to hear from you!
あなたがDIYアプリケーション容器で役に立つか、素晴らしいか、おかしく何かするならば、openshift@redhat.comで我々に連絡してください、さもなければ、OpenShift Forumsの上で我々に言うか、freenode.net #openshiftでIRCに来てください。 我々は、あなたから連絡をもらいたいです!


0 件のコメント:

コメントを投稿