@@ -21,7 +21,7 @@ def initialize
2121 @app_root_folder = File . join ( ENV [ 'PROGRAMDATA' ] , "Amazon/CodeDeploy" )
2222 InstanceAgent ::Platform . util = InstanceAgent ::WindowsUtil
2323
24- cert_dir = File . expand_path ( File . join ( File . dirname ( __FILE__ ) , '..\ certs' ) )
24+ cert_dir = File . join ( @app_root_folder , 'certs' )
2525 Aws . config [ :ssl_ca_bundle ] = File . join ( cert_dir , 'ca-bundle.crt' )
2626 ENV [ 'AWS_SSL_CA_DIRECTORY' ] = File . join ( cert_dir , 'ca-bundle.crt' )
2727 ENV [ 'SSL_CERT_FILE' ] = File . join ( cert_dir , 'ca-bundle.crt' )
@@ -34,10 +34,9 @@ def description
3434
3535 def service_main
3636 read_config
37- @attempt_count = 0
3837 log ( :info , 'started' )
39- shutdown_flag = false
40- while running? && !shutdown_flag
38+ shutdown_flag = false
39+ while running? && !shutdown_flag
4140 with_error_handling do
4241 # Initialize the poller only once
4342 begin
@@ -61,15 +60,15 @@ def service_stop
6160 log ( :info , 'stopping the agent' )
6261 @polling_mutex . synchronize do
6362 @runner . graceful_shutdown
64- log ( :info , 'agent exiting now' )
63+ log ( :info , 'command execution threads shutdown, agent exiting now' )
6564 end
6665 end
6766
6867 def log ( severity , message )
69- raise ArgumentError , "Unknown severity #{ severity . inspect } " unless InstanceAgent ::Log ::SEVERITIES . include? ( severity . to_s )
70- InstanceAgent ::Log . send ( severity . to_sym , "#{ description } : #{ message } " )
68+ raise ArgumentError , "Unknown severity #{ severity . inspect } " unless InstanceAgent ::Log ::SEVERITIES . include? ( severity . to_s )
69+ InstanceAgent ::Log . send ( severity . to_sym , "#{ description } : #{ message } " )
7170 end
72-
71+
7372 def expand_conf_path ( key )
7473 tmp = InstanceAgent ::Config . config [ key . to_sym ]
7574 InstanceAgent ::Config . config ( key . to_sym => File . join ( ENV [ 'PROGRAMDATA' ] , tmp ) ) unless Pathname . new ( tmp ) . absolute?
@@ -78,7 +77,7 @@ def expand_conf_path(key)
7877 def read_config
7978 default_config = File . join ( @app_root_folder , "conf.yml" )
8079 InstanceAgent ::Config . config ( { :config_file => default_config ,
81- :on_premises_config_file => File . join ( default_root , "conf.onpremises.yml" ) } )
80+ :on_premises_config_file => File . join ( @app_root_folder , "conf.onpremises.yml" ) } )
8281 InstanceAgent ::Config . load_config
8382
8483 expand_conf_path ( :root_dir )
@@ -89,23 +88,13 @@ def read_config
8988
9089 def with_error_handling
9190 yield
92- rescue Seahorse ::Client ::NetworkingError => e
93- @attempt_count = @attempt_count + 1
94- if @attempt_count > 3
95- log ( :error , "Failed to recover after certificate issue:" + e . inspect )
96- exit
97- end
98- log ( :error , "Custom:" + e . inspect )
99- # try to copy certs from application root folder
100- @certs_backup_folder = File . join ( @app_root_folder , "certs/." )
101- FileUtils . cp_r ( @certs_backup_folder , @cert_dir )
10291 rescue SocketError => e
10392 log ( :info , "#{ description } : failed to run as the connection failed! #{ e . class } - #{ e . message } - #{ e . backtrace . join ( "\n " ) } " )
10493 sleep InstanceAgent ::Config . config [ :wait_after_connection_problem ]
10594 rescue Exception => e
10695 if ( e . message . to_s . match ( /throttle/i ) || e . message . to_s . match ( /rateexceeded/i ) rescue false )
10796 log ( :error , "#{ description } : ran into throttling - waiting for #{ InstanceAgent ::Config . config [ :wait_after_throttle_error ] } s until retrying" )
108- sleep InstanceAgent ::Config . config [ :wait_after_throttle_error ]
97+ sleep InstanceAgent ::Config . config [ :wait_after_throttle_error ]
10998 else
11099 log ( :error , "#{ description } : error during start or run: #{ e . class } - #{ e . message } - #{ e . backtrace . join ( "\n " ) } " )
111100 sleep 5
0 commit comments