File tree Expand file tree Collapse file tree 3 files changed +33
-11
lines changed
Expand file tree Collapse file tree 3 files changed +33
-11
lines changed Original file line number Diff line number Diff line change @@ -417,6 +417,22 @@ namespace :server do
417417 end
418418 end
419419
420+ # ========================================
421+ # サーバー状態確認タスク
422+ # ========================================
423+ desc "サーバーの詳細状態を確認"
424+ task :status , [ :server_name ] => [ :check_api_credentials ] do |t , args |
425+ server_name = args [ :server_name ]
426+
427+ unless server_name
428+ abort "❌ エラー: サーバー名が必要です\n " \
429+ "使い方: rake server:status[coderdojo-japan]"
430+ end
431+
432+ puts "🔍 サーバー状態を確認中: #{ server_name } "
433+ sh "ruby scripts/utils/check_server_status.rb #{ server_name } " , verbose : false
434+ end
435+
420436 # ========================================
421437 # 個別サーバー作成タスク(テスト用)
422438 # ========================================
Original file line number Diff line number Diff line change @@ -147,12 +147,14 @@ def perform_init_params
147147 zone : "29001" , # サンドボックス
148148 zone_id : "tk1v" ,
149149 packet_filter_id : '112900927419' , # See https://secure.sakura.ad.jp/cloud/iaas/#!/network/packetfilter/.
150+ verbose : ENV [ 'VERBOSE' ] == 'true' # デバッグモード
150151 }
151152 else
152153 {
153154 zone : "31002" , # 石狩第二
154155 zone_id : "is1b" , # 石狩第二
155156 packet_filter_id : '112900922505' , # See https://secure.sakura.ad.jp/cloud/iaas/#!/network/packetfilter/.
157+ verbose : ENV [ 'VERBOSE' ] == 'true' # デバッグモード
156158 }
157159 end
158160 end
@@ -167,9 +169,11 @@ def initial_archive_id
167169 # https://manual.sakura.ad.jp/cloud/server/os-packages/archive-iso/list.html
168170 puts "- Name: #{ arch [ 'Name' ] } "
169171 # 通常版Ubuntu 24.04を使用(disk/config APIでSSH鍵設定、@notesでスタートアップスクリプト実行)
170- if /ubuntu/i =~ arch [ 'Name' ] && /24\. 04/i =~ arch [ 'Name' ] && !( /cloudimg/i =~ arch [ 'Name' ] ) then
172+ # "Ubuntu Server"で始まるものだけを対象にして、CData Syncなどを除外
173+ if /^Ubuntu Server/i =~ arch [ 'Name' ] && /24\. 04/i =~ arch [ 'Name' ] && !( /cloudimg/i =~ arch [ 'Name' ] ) then
171174 archiveid = arch [ 'ID' ]
172175 selected_name = arch [ 'Name' ]
176+ break # 最初にマッチしたものを使用
173177 end
174178 end
175179
Original file line number Diff line number Diff line change @@ -324,28 +324,30 @@ def stop_server(server_id)
324324 private
325325
326326 def _put_ssh_key ( disk_id )
327- # disk/config APIを使用してSSH鍵を設定
327+ # disk/config APIを使用してSSH鍵とスタートアップスクリプトを設定
328328 body = {
329329 SSHKey : {
330330 PublicKey : @pubkey
331331 } ,
332332 Notes : @notes
333333 }
334334 puts "DEBUG: Setting SSH key via disk/config API" if @verbose
335- send_request ( 'put' , "disk/#{ disk_id } /config" , body )
335+ puts "DEBUG: Notes being set: #{ @notes . inspect } " if @verbose
336+ puts "DEBUG: Full body for disk/config: #{ body . inspect } " if @verbose
337+ result = send_request ( 'put' , "disk/#{ disk_id } /config" , body )
338+ puts "DEBUG: disk/config API response: #{ result . inspect } " if @verbose && result
339+ result
336340 end
337341
338342 def _copying_image
339- # SSH鍵はdisk /config APIで設定済み
340- # スタートアップスクリプトはサーバー起動時に指定する必要がある
343+ # SSH鍵とスタートアップスクリプトはdisk /config APIで設定済み
344+ # /server/{id}/power APIはパラメータなしで呼び出す(Notesパラメータは無視される)
341345
342- puts "DEBUG: Starting server with startup script ID: #{ @notes . first [ :ID ] } " if @verbose
346+ puts "DEBUG: Starting server ( startup script already embedded in disk) " if @verbose
343347
344- # サーバー起動時にスタートアップスクリプトIDを指定
345- body = {
346- Notes : @notes
347- }
348- send_request ( 'put' , "server/#{ @server_id } /power" , body )
348+ # サーバー起動(パラメータなし)
349+ # Note: スタートアップスクリプトはdisk/config APIで既に設定済み
350+ send_request ( 'put' , "server/#{ @server_id } /power" , nil )
349351
350352 rescue => exception
351353 puts exception
You can’t perform that action at this time.
0 commit comments