developer's diary

最近はc#のエントリが多いです

CDPのBootstrapパターンの片鱗に触れてみる。cloudinitでgithubからwebサイトを取得してhttpd起動する。

CDPのBootstrapパターンの片鱗に触れてみる。ec2-request-spot-instancesでcloudinitでhttpd起動まで。の続きです。

cloudinitでgithubからサイト情報を取得して、httpdを起動する。という内容です。

#!/bin/bash

AMI='ami-xxxxxxxx';
INSTANCE_TYPE='t1.micro';
PRICE='.003';
SUBNET='subnet-xxxxxxxx';
KEYPAIR='xxxxxxxx';
SECURITYGROUP='sg-xxxxxxxx';
DATA='#cloud-config

packages:
  - httpd
  - httpd-devel
  - git

runcmd:
  - [/sbin/chkconfig, httpd, on]
  - [/etc/init.d/httpd, start]
  - [ git, clone, "https://github.com/mitsugeek/mitsugeek.net.git", "/var/www/html"]
';

#スポットインスタンスのリクエストを行う
SIR_ID=` ec2rsi $AMI -t $INSTANCE_TYPE -p $PRICE -n 1 -r one-time -s $SUBNET -k $KEYPAIR -g $SECURITYGROUP -d "$DATA" | awk '{if(NR==1) print $2;}' `

~~~~省略~~~~

省略部分はawsでVPC内にスポットインスタンスをリクエストしてEIP割り当てるまでのbashスクリプトと同じです。

5分くらいまつと、IPアドレスの情報が出力されるのでsafariでアクセス。

f:id:mitsugi-bb:20130417005952p:plain

PHPの環境であれば↓な感じ?

#!/bin/bash

AMI='ami-xxxxxxx';
INSTANCE_TYPE='t1.micro';
PRICE='.003';
SUBNET='subnet-xxxxxxxx';
KEYPAIR='xxxxxxxx';
SECURITYGROUP='sg-xxxxxxxx';
DATA='#cloud-config
repo_upgrade: all
packages:
  - httpd
  - httpd-devel
  - php
  - php-devel
  - php-pecl-apc
  - php-gd
  - php-mbstring
  - php-pdo
  - php-mcrypt-php

runcmd:
  - [cp, /usr/share/zoneinfo/Asia/Tokyo, /etc/localtime]
  - [sed, -i, 's/LANG="en_US.UTF-8"/LANG="ja_JP.UTF-8"/', /etc/sysconfig/i18n]
  - [/sbin/chkconfig, httpd, on]
  - [/etc/init.d/httpd, start]
';

#スポットインスタンスのリクエストを行う
SIR_ID=` ec2rsi $AMI -t $INSTANCE_TYPE -p $PRICE -n 1 -r one-time -s $SUBNET -k $KEYPAIR -g $SECURITYGROUP -d "$DATA" | awk '{if(NR==1) print $2;}' `

参考