AWS OpsWorksで起動されたインスタンスの中身を見てみる

AWS OpsWorksを使ってHAProxyのレイヤーを追加し、HAProxyインスタンスを立ち上げてみる。

自分のkeypairを使うように設定すれば、SSHでログインすることができる。

早速ログインしてみる。
ec2-userでログインができた。

OpsWorksの動作に関連しそうなものは以下のディレクトリにあった。

[ec2-user@stratus aws]$ sudo ls opsworks/current/bin
chef-client               gli             opsworks-agent-cli        restclient
chef-solo                 knife           opsworks-agent-installer  s3curl.pl
convert_to_should_syntax  lockrun         opsworks-agent-updater    shef
edit_json.rb              nokogiri        prettify_json.rb          thor
erubis                    ohai            rake
extract                   opsworks-agent  rake2thor

chef-soloやchef-client, opsworks-agent-cliなどがある。
AWSのドキュメントには、それぞれのインスタンスでchef-soloが動いていると書かれていた。
以下抜粋

Here's how it works: Chef Solo runs on every instance, and AWS OpsWorks sends commands to each instance to run recipes that set up, configure, and shut down the instance. You can extend these actions with your own custom recipes. You can also run your custom recipes on a specific instance or on all instances in your stack. 

さらにopsworks-agent-cliで以下のようなコマンドも実行できる。

  • agent_report
  • get_json
  • instance_report
  • list_commands
  • run_command
  • show_log
  • stack_state

詳細は以下。
http://docs.aws.amazon.com/opsworks/latest/userguide/agent.html

試しにget_jsonコマンドを実行してみた。(環境をまるさらしだが、すぐ消すので良しとしよう。。)

$ sudo opsworks/current/bin/opsworks-agent-cli get_json
{
  "recipes": [
    "opsworks_custom_cookbooks::load",
    "opsworks_ganglia::configure-client",
    "ssh_users",
    "agent_version",
    "haproxy::configure",
    "opsworks_stack_state_sync",
    "opsworks_custom_cookbooks::execute",
    "test_suite",
    "opsworks_cleanup"
  ],
  "opsworks_bundler": {
    "version": "1.0.10",
    "manage_package": null
  },
  "opsworks_rubygems": {
    "version": "1.8.24"
  },
  "opsworks": {
    "deployment": null,
    "valid_client_activities": [
      "reboot",
      "stop",
      "setup",
      "configure",
      "update_dependencies",
      "install_dependencies",
      "update_custom_cookbooks",
      "execute_recipes"
    ],
    "applications": [
      {
        "application_type": "php",
        "slug_name": "php_app",
        "name": "php-app"
      }
    ],
    "ruby_version": "1.8.7",
    "activity": "configure",
    "ruby_stack": "ruby_enterprise",
    "stack": {
      "name": "SampleStack3"
    },
    "instance": {
      "ip": null,
      "id": "3d9fc521-1bfa-4d82-b74c-f0761383394c",
      "private_ip": "10.132.159.132",
      "aws_instance_id": "i-d75147d4",
      "backends": 5,
      "layers": [
        "lb"
      ],
      "public_dns_name": null,
      "hostname": "stratus",
      "region": "ap-northeast-1",
      "instance_type": "m1.small",
      "availability_zone": "ap-northeast-1a",
      "private_dns_name": "ip-10-132-159-132.ap-northeast-1.compute.internal",
      "architecture": "i386"
    },
    "agent_version": "104",
    "layers": {
      "lb": {
        "id": "f64dc03e-0c01-4f41-b588-b8289e03deca",
        "name": "Load Balancer",
        "instances": {
          "stratus": {
            "ip": null,
            "elastic_ip": "54.249.245.56",
            "private_ip": "10.132.159.132",
            "aws_instance_id": "i-d75147d4",
            "created_at": "2013-03-13T06:38:58+00:00",
            "status": "online",
            "booted_at": "2013-03-13T06:40:49+00:00",
            "backends": 5,
            "public_dns_name": null,
            "region": "ap-northeast-1",
            "instance_type": "m1.small",
            "availability_zone": "ap-northeast-1a",
            "private_dns_name": "ip-10-132-159-132.ap-northeast-1.compute.internal"
          }
        }
      },
      "php-app": {
        "id": "c38c9a7f-90eb-4764-8ebd-3b48592f57cb",
        "name": "PHP Application Server",
        "instances": {
          "altocumulus": {
            "ip": "54.249.207.244",
            "elastic_ip": null,
            "private_ip": "10.162.54.166",
            "aws_instance_id": "i-2b5d4b28",
            "created_at": "2013-03-13T06:48:12+00:00",
            "status": "online",
            "booted_at": "2013-03-13T06:49:30+00:00",
            "backends": 5,
            "public_dns_name": "ec2-54-249-207-244.ap-northeast-1.compute.amazonaws.com",
            "region": "ap-northeast-1",
            "instance_type": "m1.small",
            "availability_zone": "ap-northeast-1a",
            "private_dns_name": "ip-10-162-54-166.ap-northeast-1.compute.internal"
          },
          "stratocumulus": {
            "ip": "54.249.153.134",
            "elastic_ip": null,
            "private_ip": "10.152.46.168",
            "aws_instance_id": "i-07405604",
            "created_at": "2013-03-13T07:30:05+00:00",
            "status": "online",
            "booted_at": "2013-03-13T07:31:22+00:00",
            "backends": 5,
            "public_dns_name": "ec2-54-249-153-134.ap-northeast-1.compute.amazonaws.com",
            "region": "ap-northeast-1",
            "instance_type": "m1.small",
            "availability_zone": "ap-northeast-1a",
            "private_dns_name": "ip-10-152-46-168.ap-northeast-1.compute.internal"
          }
        }
      }
    },
    "sent_at": 1363160598,
    "rails_stack": {
      "name": null
    }
  },
  "opsworks_custom_cookbooks": {
    "recipes": [

    ],
    "enabled": false
  },
  "deploy": {
    "php_app": {
      "memcached": {
        "host": null,
        "port": 11211
      },
      "rails_env": null,
      "migrate": false,
      "ssl_certificate_ca": null,
      "auto_bundle_on_deploy": true,
      "ssl_support": false,
      "domains": [
        "php_app"
      ],
      "database": {
        "reconnect": true,
        "host": null,
        "database": "php_app",
        "password": null,
        "username": "root"
      },
      "ssl_certificate": null,
      "symlink_before_migrate": {
        "config/opsworks.php": "opsworks.php"
      },
      "application_type": "php",
      "symlinks": {
      },
      "mounted_at": null,
      "restart_command": "echo 'restarting app'",
      "document_root": null,
      "sleep_before_restart": 0,
      "application": "php_app",
      "deploy_to": "/srv/www/php_app",
      "scm": {
        "user": null,
        "repository": "git://github.com/funasaki/helloworld-php.git",
        "password": null,
        "revision": null,
        "scm_type": "git",
        "ssh_key": null
      },
      "ssl_certificate_key": null
    }
  },
  "haproxy": {
    "static_applications": {
    },
    "health_check_method": "GET",
    "rails_applications": {
    },
    "nodejs_backends": [

    ],
    "php_applications": {
      "php_app": {
        "domains": [
          "php_app"
        ],
        "application_type": "php",
        "mounted_at": null
      }
    },
    "enable_stats": true,
    "nodejs_applications": {
    },
    "php_backends": [
      {
        "ip": "10.162.54.166",
        "backends": 10,
        "name": "altocumulus"
      },
      {
        "ip": "10.152.46.168",
        "backends": 10,
        "name": "stratocumulus"
      }
    ],
    "rails_backends": [

    ],
    "stats_url": "/haproxy?stats",
    "static_backends": [

    ],
    "stats_password": "mypassword",
    "stats_user": "opsworks",
    "health_check_url": "/"
  },
  "ssh_users": {
  }
}

さらにログファイルも当然だがあった。

$ ls /var/log/aws/opsworks
installer.log           opsworks-agent.log  user-data.log
opsworks-agent-cli.log  updater.log