詳細検索

AWSメンテナンスでstoppingのまま停止しない障害の対応

アバター
著者: komi

AWSメンテナンスでstoppingのまま停止しない障害の対応

こんにちは。小宮です。

タイトルどおり障害がありまして、今後の為に記録しておこうかと思います。

AWSメンテ通知の来たインスタンスをStopしたところ、最終的には6時間強ほどstoppingのままでした。
今回のインスタンスは、自分で構築したわけでなく、構築メモは残っているもののメンテナンスされていない、
という状況把握が難しいパターンでした。
一応上がってるプロセスとポートくらいは控えてから止めましたが、snapshotは撮ってなくAMIも作っていませんでした。

日本語フォーラムに投稿したところ特に反応がありませんでした。
聞いた話によると英語フォーラムを使えば15分くらいで対応してもらえることもあるようです。

その間、stoppingのインスタンスのsnapshotを撮ってAMI作成してそこから新インスタンスを起動してみましたが、
NICの設定の問題かなにかで接続できませんでした。
microインスタンスを起動しapacheだけ入れて簡単なsorryページを設置しました。

stoppingのまま6時間ほど待ったのですが一向に進捗せず、
しかもサポートにも未加入だったので、サポートに申し込んで以下のように問い合わせをしました。
(申し込んだら10分くらいで反映されました)。
--------------------------------- 1回目:
EC2 Management ConsoleからサーバをStopしましたが、Stoppingから進みません。
http://aws.amazon.com/jp/instance-help/
に従い、何度かForce Stopを試みましたが同様のため、強制停止をお願いしたいです。

Zone: ap-northeast-1a
Instance: i-4a42a348

インスタンスID: i-4a42a348
--------------------------------- 2回目:

先ほどstopしました。何か対応されましたでしょうか。
同じインスタンスをstartしたいのですが、2回ほどstartしてもstopされてしまいます。
可能なら起動をお願いできますでしょうか。
--------------------------------- 私が時短なので帰宅後、stopedになってから選べたCreateImageでAMIを作って新インスタンスを起動したら接続できたようです。

翌朝みたらサポートから返事が来ていました。
--------------------------------- サポートの方から:
お問い合わせ誠にありがとうございます。

i-4a42a348についてお調べしたところ、仮想サーバホストに問題が発生していたためインスタンスの停止にお時間を要しておりました。
EC2では、長時間StoppingやShuttingdownの状態が続いているインスタンスを自動でクリーンアップする仕組みがございます。
今回はこちらの仕組みによってインスタンスのStopが行われておりました。
このたびはご迷惑をおかけし、申し訳ございませんでした。

インスタンスが起動できない件については、インスタンスとEBSボリュームの関連付けに問題が発生しており、その影響でインスタンスが起動しない状態となっているようです。
お手数をおかけしますが、インスタンスにアタッチされているボリュームをデタッチ/アタッチして再度インスタンスの起動をお試しいただけるでしょうか。
通常のデタッチが効かない場合、Force Detachをお試しください。

ボリュームのデタッチ/アタッチを行ってもインスタンスが起動しない場合、恐れ入りますが、再度ご連絡いただけるでしょうか。

ご不明な点がありましたらお知らせください。
よろしくお願いいたします。
---------------------------------

ということで以下作業を行いました。

まずマウントポイントを控える
Attachment:
i-4a42a348 (devlab):/dev/sda1 (attached)

インスタンスを選択しforce detachを実行、再度同じマウントポイントにattachし、
インスタンスをstartしてみたところ、startしました。

セキュリティグループのdefaultが入ってなくて渡れなかったので入れときました。
で、sshで渡れるようになりました。AWS的な対応はここまでです。

入ったら上がってるポートが前と違うようでしたので修正しました。

[shell]# netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1275/mysqld tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1374/httpd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 901/sshd tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1356/php-fpm[/shell]
事前に控えておいたものと見比べると、apacheじゃなくてnginxが上がってないとダメです。
それとnodeとmongodが上がっていない。

[shell]# chkconfig --list|grep 3:on abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrt-oops 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off getsshkey 0:off 1:off 2:off 3:on 4:on 5:off 6:off haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off irqbalance 0:off 1:off 2:off 3:on 4:on 5:on 6:off kdump 0:off 1:off 2:off 3:on 4:on 5:on 6:off libvirt-guests 0:off 1:off 2:on 3:on 4:on 5:on 6:off messagebus 0:off 1:off 2:on 3:on 4:on 5:on 6:off mongod 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off udev-post 0:off 1:on 2:on 3:on 4:on 5:on 6:off

# service nginx start nginx を起動中: Setting option from ("on") Setting option from ("RewriteLevel", "CoreFilters") Setting option from ("FileCachePath", "/var/cache/ngx_pagespeed") Setting option from ("EnableFilters", "collapse_whitespace,add_instrumentation,remove_comments") nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] still could not bind() [0905/105718:INFO:google_message_handler.cc(33)] Shutting down ngx_pagespeed root [失敗][/shell]
apacheが先に起動してしまい使ってるポートがnginxとかぶって起動しなかったようです。

[shell]# chkconfig httpd off # service httpd stop httpd を停止中: [ OK ] # service nginx start nginx を起動中: Setting option from ("on") Setting option from ("RewriteLevel", "CoreFilters") Setting option from ("FileCachePath", "/var/cache/ngx_pagespeed") Setting option from ("EnableFilters", "collapse_whitespace,add_instrumentation,remove_comments") [ OK ] # netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1275/mysqld tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 901/sshd tcp 0 0 0.0.0.0:10080 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1356/php-fpm

# chkconfig --list|grep 3:on abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrt-oops 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off getsshkey 0:off 1:off 2:off 3:on 4:on 5:off 6:off haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off irqbalance 0:off 1:off 2:off 3:on 4:on 5:on 6:off kdump 0:off 1:off 2:off 3:on 4:on 5:on 6:off libvirt-guests 0:off 1:off 2:on 3:on 4:on 5:on 6:off messagebus 0:off 1:off 2:on 3:on 4:on 5:on 6:off mongod 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off udev-post 0:off 1:on 2:on 3:on 4:on 5:on 6:off[/shell]
nginxは起動しまして起動スクリプト的な調整も行いました。

foreverのプロセスは上がっていない模様です。
node.jsのプロセスをforeverで永続化したようですが、特に手順は見つからなかったのでヒストリを見ました。

[shell]# forever list info: No forever processes running

# grep forever /root/.bash_history npm install -g forever npm install -g forever forever start app.js forever --minUptime 1000ms --spinSleepTime 1000ms start app.js forever stop app.js forever --minUptime 1000ms --spinSleepTime 1000ms start app.js forever list forever list forever stop forever list forever config forever stopall forever list forever start app & forever start app.js & forever stop forever stop app.js forever start app.js & forever stop app.js forever start app.js & forever app & forever app.js forever start app.js forever list which forever forever list[/shell]
app.jsの場所がわからないので探してみました。
foreverでstartする手前のcdコマンドを見たらg****(たぶんプロダクト名)という場所に移動していました。

[shell]# find / -name "g****" /usr/local/lib/src/g**** # ls /usr/local/lib/src/g**** app.js index.html package.json routes web.config iisnode.yml node_modules public views[/shell]
これっぽいので起動してみます。
[shell]# cd /usr/local/lib/src/g**** # forever --minUptime 1000ms --spinSleepTime 1000ms start app.js info: Forever processing file: app.js # forever list info: Forever processes running data: uid command script forever pid logfile uptime data: [0] WlVc /usr/local/bin/node app.js 3717 3719 /root/.forever/WlVc.log 0:0:0:23.169

# netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1234/mysqld tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 3619/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3619/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 860/sshd tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 3719/node tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1361/master tcp 0 0 0.0.0.0:10080 0.0.0.0:* LISTEN 3619/nginx tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1415/php-fpm[/shell]

node起動したようです。

次はmongodです。

[shell]# service mongod start mongod を起動中: bash: /var/log/mongodb/mongodb.log: 許可がありません [ OK ] # netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1275/mysqld tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 901/sshd tcp 0 0 0.0.0.0:10080 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1356/php-fpm # ls -lh /var/log/mongodb/mongodb.log -rw-r--r-- 1 root root 0 5月 5 03:40 2013 /var/log/mongodb/mongodb.log # ls -lh /var/log/mongodb 合計 176K -rw-r--r-- 1 root root 0 5月 5 03:40 2013 mongodb.log -rw-r--r-- 1 mongodb mongodb 485 4月 7 03:08 2013 mongodb.log-20130331.gz -rw-r--r-- 1 mongodb mongodb 90 4月 14 03:07 2013 mongodb.log-20130407.gz -rw-r--r-- 1 mongodb mongodb 1.6K 4月 21 03:18 2013 mongodb.log-20130414.gz -rw-r--r-- 1 mongodb mongodb 327 4月 28 03:46 2013 mongodb.log-20130421.gz -rw-r--r-- 1 mongodb mongodb 24K 5月 5 03:40 2013 mongodb.log-20130428.gz -rw-r--r-- 1 root root 1.4K 5月 5 03:40 2013 mongodb.log-20130505 -rw-r--r-- 1 mongodb mongodb 0 3月 31 03:10 2013 mongodb.log.2013-03-30T18-10-01 -rw-r--r-- 1 mongodb mongodb 0 4月 7 03:08 2013 mongodb.log.2013-04-06T18-08-01 -rw-r--r-- 1 mongodb mongodb 0 4月 14 03:07 2013 mongodb.log.2013-04-13T18-07-01 -rw-r--r-- 1 mongodb mongodb 0 4月 21 03:18 2013 mongodb.log.2013-04-20T18-18-01 -rw-r--r-- 1 mongodb mongodb 0 4月 28 03:46 2013 mongodb.log.2013-04-27T18-46-01 -rw-r--r-- 1 mongodb mongodb 38K 5月 2 10:10 2013 mongodb.log.2013-05-02T01-10-07 -rw-r--r-- 1 mongodb mongodb 2.4K 5月 2 10:10 2013 mongodb.log.2013-05-02T01-10-54 -rw-r--r-- 1 mongodb mongodb 15K 5月 2 14:48 2013 mongodb.log.2013-05-02T05-48-24 -rw-r--r-- 1 mongodb mongodb 64K 7月 17 18:04 2013 mongodb.log.2013-05-02T05-53-38[/shell]

パーミッション的にログが書けないから上がってない模様。

[shell]# chown -R mongodb. /var/log/mongodb # service mongod start mongod を起動中: [ OK ] # netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1275/mysqld tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 901/sshd tcp 0 0 0.0.0.0:10080 0.0.0.0:* LISTEN 1570/nginx tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1356/php-fpm[/shell]

ログのパーミッションは直したけど起動しない。ログは出るようになりました。

[shell]Thu Sep 5 11:07:06 [initandlisten] options: { bind_ip: "127.0.0.1", command: [ "run" ], config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", fork: "true", logpath: "/var/log/mongodb/mongodb.log", nohttpinterface: "true", nojournal: "true", pidfilepath: "/var/run/mongodb/mongodb.pid", port: 27017, quiet: true } ************** Unclean shutdown detected. Please visit http://dochub.mongodb.org/core/repair for recovery instructions. ************* Thu Sep 5 11:07:06 [initandlisten] exception in initAndListen: 12596 old lock file, terminating Thu Sep 5 11:07:06 dbexit: Thu Sep 5 11:07:06 [initandlisten] shutdown: going to close listening sockets... Thu Sep 5 11:07:06 [initandlisten] shutdown: going to flush diaglog... Thu Sep 5 11:07:06 [initandlisten] shutdown: going to close sockets... Thu Sep 5 11:07:06 [initandlisten] shutdown: waiting for fs preallocator... Thu Sep 5 11:07:06 [initandlisten] shutdown: closing all files... Thu Sep 5 11:07:06 [initandlisten] closeAllFiles() finished Thu Sep 5 11:07:06 dbexit: really exiting now

rm -f /var/run/mongodb/mongodb.pid[/shell] pidファイルを消しても上がらない。
データファイルの不整合が起こっているのでリカバリを行わなければならないようなメッセージです。

mongodのリペアなんてしたことないのでログに出てたページとログ見て対応してみることにします。
http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/ [shell]Thu Sep 5 11:07:06 [initandlisten] options: { bind_ip: "127.0.0.1", command: [ "run" ], config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", fork: "true", logpath: "/var/log/mongodb/mongodb.log", nohttpinterface: "true", nojournal: "true", pidfilepath: "/var/run/mongodb/mongodb.pid", port: 27017, quiet: true }[/shell]

自分の英語の解釈が違っていたら大変なことになるので日本語の記事がないか検索してしまいました。
http://kaworu.jpn.org/kaworu/2012-12-26-1.php

データディレクトリを確認してみます。

[shell]# ll /var/lib/mongodb/ 合計 688152 drwxr-xr-x 2 mongodb mongodb 4096 5月 31 10:57 2013 _tmp -rw------- 1 mongodb mongodb 67108864 7月 17 18:04 2013 devlab_db.0 -rw------- 1 mongodb mongodb 134217728 4月 9 16:26 2013 devlab_db.1 -rw------- 1 mongodb mongodb 16777216 7月 17 18:04 2013 devlab_db.ns drwxr-xr-x 2 mongodb mongodb 4096 5月 2 15:50 2013 journal -rwxr-xr-x 1 mongodb mongodb 6 5月 2 14:48 2013 mongod.lock -rw------- 1 mongodb mongodb 67108864 4月 30 14:33 2013 sugatest.0 -rw------- 1 mongodb mongodb 134217728 4月 30 14:33 2013 sugatest.1 -rw------- 1 mongodb mongodb 268435456 4月 24 17:47 2013 sugatest.2 -rw------- 1 mongodb mongodb 16777216 4月 30 14:33 2013 sugatest.ns[/shell]

リペアコマンドを実施します。
[shell]# mongod --dbpath /var/lib/mongodb --repair Thu Sep 5 14:25:47 [initandlisten] MongoDB starting : pid=3941 port=27017 dbpath=/var/lib/mongodb 64-bit host=devlab Thu Sep 5 14:25:47 [initandlisten] db version v2.2.3, pdfile version 4.5 Thu Sep 5 14:25:47 [initandlisten] git version: nogitversion Thu Sep 5 14:25:47 [initandlisten] build info: Linux buildvm-09.phx2.fedoraproject.org 2.6.32-358.2.1.el6.x86_64 #1 SMP Wed Feb 20 12:17:37 EST 2013 x86_64 BOOST_LIB_VERSION=1_41 Thu Sep 5 14:25:47 [initandlisten] options: { dbpath: "/var/lib/mongodb", repair: true } Thu Sep 5 14:25:47 [initandlisten] **** Thu Sep 5 14:25:47 [initandlisten] **** Thu Sep 5 14:25:47 [initandlisten] need to upgrade database sugatest with pdfile version 4.5, new version: 4.5 Thu Sep 5 14:25:47 [initandlisten] starting upgrade Thu Sep 5 14:25:47 [initandlisten] sugatest repairDatabase sugatest Thu Sep 5 14:25:48 [FileAllocator] allocating new datafile /var/lib/mongodb/_tmp_repairDatabase_0/sugatest.ns, filling with zeroes... ~略~ Thu Sep 5 14:25:50 [initandlisten] build index done. scanned 34 total records. 0 secs Thu Sep 5 14:25:50 [initandlisten] build index devlab_db.lanternKeywordStats { keyword: 1 } Thu Sep 5 14:25:50 [initandlisten] fastBuildIndex dupsToDrop:0 Thu Sep 5 14:25:50 [initandlisten] build index done. scanned 2 total records. 0 secs Thu Sep 5 14:25:50 [initandlisten] finished checking dbs Thu Sep 5 14:25:50 dbexit: Thu Sep 5 14:25:50 [initandlisten] shutdown: going to close listening sockets... Thu Sep 5 14:25:50 [initandlisten] shutdown: going to flush diaglog... Thu Sep 5 14:25:50 [initandlisten] shutdown: going to close sockets... Thu Sep 5 14:25:50 [initandlisten] shutdown: waiting for fs preallocator... Thu Sep 5 14:25:50 [initandlisten] shutdown: closing all files... Thu Sep 5 14:25:50 [initandlisten] closeAllFiles() finished Thu Sep 5 14:25:50 [initandlisten] shutdown: removing fs lock... Thu Sep 5 14:25:50 dbexit: really exiting now[/shell]

上記のような感じでリペアが行われましたが、
起動してみたけどまだ上がってこないのでログを見てみたところ、パーミッションに問題があるような記述が。

[shell]Thu Sep 5 14:31:35 [initandlisten] couldn't open /var/lib/mongodb/sugatest.ns errno:13 Permission denied Thu Sep 5 14:31:35 [initandlisten] error couldn't open file /var/lib/mongodb/sugatest.ns terminating[/shell]

確認したらリペア実行前と異なるパーミッションになっているので権限修正しました
[shell]# ll 合計 688160 drwxr-xr-x 2 root root 4096 9月 5 14:25 2013 devlab_db -rw------- 1 root root 67108864 9月 5 14:25 2013 devlab_db.0 -rw------- 1 root root 134217728 9月 5 14:25 2013 devlab_db.1 -rw------- 1 root root 16777216 9月 5 14:25 2013 devlab_db.ns drwxr-xr-x 2 mongodb mongodb 4096 5月 2 15:50 2013 journal -rwxr-xr-x 1 mongodb mongodb 0 9月 5 14:31 2013 mongod.lock drwxr-xr-x 2 root root 4096 9月 5 14:25 2013 sugatest -rw------- 1 root root 67108864 9月 5 14:25 2013 sugatest.0 -rw------- 1 root root 134217728 9月 5 14:25 2013 sugatest.1 -rw------- 1 root root 268435456 9月 5 14:25 2013 sugatest.2 -rw------- 1 root root 16777216 9月 5 14:25 2013 sugatest.ns # chown -R mongodb. /var/lib/mongodb # service mongod start mongod を起動中: [ OK ] # netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1234/mysqld tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 3619/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3619/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 860/sshd tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 3719/node tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1361/master tcp 0 0 0.0.0.0:10080 0.0.0.0:* LISTEN 3619/nginx tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1415/php-fpm tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 3989/mongod[/shell]

mongodも起動したようです。
とりあえずここまで。

foreverでの起動停止については、起動スクリプト作るか起動手順を整えておくなどの対処が
必要なんではないでしょうかとの指摘がございまして私もそう思います。

rc.localに起動コマンド書くだけだと上手く停止できず今回のようにstoppingしたまま停止しない
という事件が起こる可能性があります。
また、強制停止された場合にpidファイルが削除されずに残ってしまい次回起動できないというのもよくあるんで、
起動停止処理をきちんと書いた起動スクリプトの作成が望まれます。
case文でstartセクションとstopセクション書くだけでわりと簡単にできると思います。

担当の方はたしか10月まで戻ってこないので、自分でやってみます。

[shell]# ps -ef|grep forever root 3717 1 0 11:55 ? 00:00:00 /usr/local/bin/node /usr/local/lib/node_modules/forever/bin/monitor app.js root 4046 3495 0 15:08 pts/1 00:00:00 grep forever

vi /etc/init.d/forever ------------- #!/bin/bash # # chkconfig: 345 99 01 # description: start/stop script for node.js # processname: /usr/local/bin/forever # config:

# We require the /etc/delegeted.conf file, but supply it in the package, so it # should always be there. progname=forever lockfile=/var/lock/subsys/forever prog=/usr/local/bin/forever appdir=/usr/local/lib/src/g**** conffile=app.js export PATH=/usr/local/bin:$PATH

RETVAL=0

start() { echo -n $"Starting $progname: " cd $appdir && $prog --minUptime 1000ms --spinSleepTime 1000ms start $conffile RETVAL=$? echo [ $RETVAL = 0 ] && touch $lockfile return $RETVAL }

stop() { echo -n $"Stopping $progname: " cd $appdir && $prog stop $conffile RETVAL=$? echo [ $RETVAL = 0 ] && rm -f $lockfile return $RETVAL }

# See how we were called. case "$1" in start) start ;; stop) stop ;; status) $prog list RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f $lockfile ]; then stop start fi ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" exit 1 esac

exit $RETVAL -------------------------------- # chmod +x /etc/init.d/forever # chkconfig --add forever # chkconfig --list forever forever 0:off 1:off 2:off 3:on 4:on 5:on 6:off[/shell]

起動スクリプトで起動できるようになったようです。(起動させるアプリの場所等がこれで正しいのかは担当者の確認が必要な気がします)

[shell]# service forever start Starting forever: info: Forever processing file: app.js

# forever list info: Forever processes running data: uid command script forever pid logfile uptime data: [0] 9XwM /usr/local/bin/node app.js 3816 3818 /root/.forever/9XwM.log 0:0:0:7.578[/shell]

stoppingのままだったことが色々気になるので試験的にrebootしてみます。
今さらですがブラウザからじゃなくてshutdownコマンド打ったほうがよかったような気がしています。

[shell]# reboot[/shell]

もう一回ログイン

[shell]# uptime 15:55:26 up 0 min, 1 user, load average: 0.41, 0.11, 0.03

# netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1227/mysqld tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1423/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1423/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 853/sshd tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 1459/node tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1347/master tcp 0 0 0.0.0.0:10080 0.0.0.0:* LISTEN 1423/nginx tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1401/php-fpm tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 783/mongod[/shell]

rebootしても正常に起動するようになった様子です。
起動後にステータスチェックに失敗したときのトラブルシューティング方法は以下のリンクから確認できるようです。
http://docs.aws.amazon.com/ja\_jp/AWSEC2/latest/UserGuide/TroubleshootingInstances.html

・今回の教訓:
 force dettachはstartしない時の切り札だとおもいました。
 stopping中はAWSのクリーンアップ待ちになるのでAMIをしっかりとる。
 何かを追加で入れた後には自動起動の仕組みを整えてOS再起動試験したほうがいい(またはChefで管理やServerspecでテスト)
 AWSメンテナンスの前にはAMIをつくって複製可能かためしておく、ブラウザからstopでなくshutdown -h nowしたほうがいいです。
 AWSのフォーラムは英語を使うと応答が早いようです。

 個人的に、まともに同じデーモンが上がってこないとかは特に珍しいことでもない気がしますが、
 AWSのインスタンスがstopしないのは初だったので、いつもstopが上手くいくとは限らないんだなあという勉強になりました。

以上、見ていただいてありがとうございました。

Related Articles