LoginSignup
8
2

More than 5 years have passed since last update.

AWSにStackStormをインストールしてみました

Posted at

image

はじめに

StackStormとは、複数のサービスやツールを統合・自動化するイベント・ドリブンな自動化プラットフォームになります。コミニティーで提供されているPackと呼ばれるソフトウェアコンポーネントを追加することで機能を拡張することが可能です。
StackStrom Pack一覧

2016年3月にBrocadeがStackStormを買収して、商用バーションとしてBrocade Workflow Composer(以下BWC)を販売しています。BWCとStackStormの違いは、サポートと追加機能(アクセスコントロール、LDAP、ワークフローデザイナー)で、BWCの90日評価版ライセンスでお試しで使用する事も可能ですが、今回はオープンソース版のStackStormをインストールして活用方法を見出していきたいと思います。

StackStorm システム要件

Installationガイドにシステム要件とインストールが記載されてますので確認。

System Requirements

Linux (64 bit) Vagrant Box Amazon AWS AMI
Ubuntu 14.04 bento/ubuntu-14.04 Ubuntu Server 14.04 LTS (HVM)
RHEL 7 / CentOS 7 bento/centos-7.2 Red Hat Enterprise Linux (RHEL) 7.2 (HVM)
RHEL 6 / CentOS 6 bento/centos-6.7 Red Hat Enterprise Linux (RHEL) 6 (HVM)
Testing Production
Dual CPU system Quad core CPU system
1GB RAM >16GB RAM
10GB storage 40GB storage
Recommended EC2: t2.medium Recommended EC2: m4.xlarge

インストール

今回はAWS上のUbuntuサーバにインストールしますが、上記システム要件だとAWSの無料利用枠の対象外となるため、t2.microのストレージ16GBのインスタンスにインストールしたいと思います。

Ubuntu Server 16 LTSだとStackStormインストール時にエラーとなるため、Ubuntu Server 14 LTS のインスタンスを用意してください。

インスタンスにとログイン後、下記スクリプトを実行するだけで簡単にインストールできます。

curl -sSL https://stackstorm.com/packages/install.sh | bash -s -- --user=st2admin --password=<パスワード>

注意点
1) nginxをインストールするので、既にApacheなどでPort:80を使用していると、エラーでスクリプトが停止します。

問題なくインストールが完了すると下記表示となります。

####################### WARNING ########################
######## Chatops requires manual configuration #########
Edit /opt/stackstorm/chatops/st2chatops.env to specify
the adapter and settings hubot should use to connect to
the chat you're using. Don't forget to start the service
afterwards:

  $ sudo service st2chatops restart

For more information, please refer to documentation at
https://docs.stackstorm.com/install/deb.html#setup-chatops
########################################################


███████╗████████╗██████╗      ██████╗ ██╗  ██╗
██╔════╝╚══██╔══╝╚════██╗    ██╔═══██╗██║ ██╔╝
███████╗   ██║    █████╔╝    ██║   ██║█████╔╝
╚════██║   ██║   ██╔═══╝     ██║   ██║██╔═██╗
███████║   ██║   ███████╗    ╚██████╔╝██║  ██╗
╚══════╝   ╚═╝   ╚══════╝     ╚═════╝ ╚═╝  ╚═╝

  st2 is installed and ready to use.

Head to https://YOUR_HOST_IP/ to access the WebUI

Don't forget to dive into our documentation! Here are some resources
for you:

* Documentation  - https://docs.stackstorm.com
* Knowledge Base - https://stackstorm.reamaze.com

Thanks for installing StackStorm! Come visit us in our Slack Channel
and tell us how it's going. We'd love to hear from you!

Webブラウザーからhttpsで接続するとログイン画面が表示されます。ユーザは"st2admin"、パスワードはインストール時に指定したパスワードを入力しログインできたら成功です。
image

Action作成

動作確認用にSample Python actionを使用して確認したいと思います。

1) メタデータファイル (my_echo_action.yaml)の作成

・デフォルトパックにアクション作成します。

$ cd /opt/stackstorm/packs/default/actions
$ vim my_echo_action.yaml
---
name: "echo_action"
runner_type: "python-script"
description: "Print message to standard output."
enabled: true
entry_point: "my_echo_action.py"
parameters:
    message:
        type: "string"
        description: "Message to print."
        required: true
        position: 0

・ファイルのオーナー・権限を変更

$ chown root:st2packs my_echo_action.yaml
$ chmod 664 my_echo_action.yaml

2) Action スクリプトファイル (my_echo_action.py)の作成

$ vim my_echo_action.py
import sys

from st2actions.runners.pythonrunner import Action

class MyEchoAction(Action):
    def run(self, message):
        print(message)

        if message == 'working':
            return (True, message)
        return (False, message)

3) StackStormへにメタデータ読み込み
st2 action create -y my_echo_action.yaml

4) メタデータの再読み込み
アクションを変更した際は、手動で削除・再読み込みが必要となります。
又は、下記方法で全メタデータの再読み込みを実施します。

$ st2ctl reload
Registering content...[flags = --register-actions --register-aliases --register-sensors --register-triggers --register-configs --register-rules]
2016-12-05 12:46:16,487 INFO [-] Connecting to database "st2" @ "0.0.0.0:27017" as user "None".
2016-12-05 12:46:16,546 INFO [-] =========================================================
2016-12-05 12:46:16,546 INFO [-] ############## Registering triggers #####################
2016-12-05 12:46:16,547 INFO [-] =========================================================
2016-12-05 12:46:16,628 INFO [-] Registered 0 triggers.
2016-12-05 12:46:16,629 INFO [-] =========================================================
2016-12-05 12:46:16,629 INFO [-] ############## Registering sensors ######################
2016-12-05 12:46:16,629 INFO [-] =========================================================
2016-12-05 12:46:16,930 INFO [-] Registered 3 sensors.
2016-12-05 12:46:16,930 INFO [-] =========================================================
2016-12-05 12:46:16,930 INFO [-] ############## Registering actions ######################
2016-12-05 12:46:16,930 INFO [-] =========================================================
2016-12-05 12:47:34,686 INFO [-] Registered 64 actions.
2016-12-05 12:47:34,687 INFO [-] =========================================================
2016-12-05 12:47:34,688 INFO [-] ############## Registering rules ########################
2016-12-05 12:47:34,688 INFO [-] =========================================================
2016-12-05 12:47:34,759 INFO [-] Registered 1 rules.
2016-12-05 12:47:34,760 INFO [-] =========================================================
2016-12-05 12:47:34,760 INFO [-] ############## Registering aliases ######################
2016-12-05 12:47:34,760 INFO [-] =========================================================
2016-12-05 12:47:34,934 INFO [-] Registered 9 aliases.
2016-12-05 12:47:34,935 INFO [-] =========================================================
2016-12-05 12:47:34,935 INFO [-] ############## Registering configs ######################
2016-12-05 12:47:34,935 INFO [-] =========================================================
2016-12-05 12:47:34,936 INFO [-] Registered 0 configs.
##### st2 components status #####
st2actionrunner PID: 842
st2api PID: 767
st2api PID: 1295
st2stream PID: 768
st2stream PID: 1290
st2auth PID: 758
st2auth PID: 1293
st2garbagecollector PID: 757
st2notifier PID: 761
st2resultstracker PID: 759
st2rulesengine PID: 765
st2sensorcontainer PID: 751
st2chatops is not running.
mistral-server PID: 860
mistral-api PID: 829
mistral-api PID: 2554
mistral-api PID: 2555

確認

1 ) Packの追加インストール
このまま実行すると以下の様にエラーがでてしまいます。

$ st2 run default.echo_action message=working
id: 58462044cd37df050fb3d6dc
status: failed (0s elapsed)
parameters:
  message: 'working'
result:
  error: '

    Virtual environment (/opt/stackstorm/virtualenvs/default) for pack "default" doesn''t exist. If you haven''t

    installed a pack using "packs.install" command, you can create a new virtual environment using

    "st2 run packs.setup_virtualenv packs=default" command''

    '
  traceback: "  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2actions/container/base.py", line 98, in _do_run
    (status, result, context) = runner.run(action_params)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2actions/runners/pythonrunner.py", line 118, in run
    raise Exception(msg)
"

Packでの仮想環境が必要との事なので、エラー内容のとおり下記方法で追加のPackをインストールします。
st2 run packs.setup_virtualenv packs=default

2) アクションの実行
このPythonアクションは、"message"パラメータで提供されたテキストを標準出力に表示し、パラメータがworkingであれば、Trueを返します。

$ st2 run default.echo_action message=working
.
id: 58462289cd37df050fb3d6f1
status: succeeded
parameters:
  message: working
result:
  exit_code: 0
  result: working
  stderr: ''
  stdout: 'working

パラメータがworking以外であれば、Falseを返します。

$ st2 run default.echo_action message=test
.
id: 58462292cd37df050fb3d6f4
status: failed
parameters:
  message: test
result:
  exit_code: 0
  result: test
  stderr: ''
  stdout: 'test

新規アクションの追加まで確認がとれたので、次回はRule, Senser, Triger(Webhook)などを使用してみたいと思います。

8
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2