@@ -21,7 +21,7 @@ def initialize
21
21
@app_root_folder = File . join ( ENV [ 'PROGRAMDATA' ] , "Amazon/CodeDeploy" )
22
22
InstanceAgent ::Platform . util = InstanceAgent ::WindowsUtil
23
23
24
- cert_dir = File . expand_path ( File . join ( File . dirname ( __FILE__ ) , '..\ certs' ) )
24
+ cert_dir = File . join ( @app_root_folder , 'certs' )
25
25
Aws . config [ :ssl_ca_bundle ] = File . join ( cert_dir , 'ca-bundle.crt' )
26
26
ENV [ 'AWS_SSL_CA_DIRECTORY' ] = File . join ( cert_dir , 'ca-bundle.crt' )
27
27
ENV [ 'SSL_CERT_FILE' ] = File . join ( cert_dir , 'ca-bundle.crt' )
@@ -34,10 +34,9 @@ def description
34
34
35
35
def service_main
36
36
read_config
37
- @attempt_count = 0
38
37
log ( :info , 'started' )
39
- shutdown_flag = false
40
- while running? && !shutdown_flag
38
+ shutdown_flag = false
39
+ while running? && !shutdown_flag
41
40
with_error_handling do
42
41
# Initialize the poller only once
43
42
begin
@@ -61,15 +60,15 @@ def service_stop
61
60
log ( :info , 'stopping the agent' )
62
61
@polling_mutex . synchronize do
63
62
@runner . graceful_shutdown
64
- log ( :info , 'agent exiting now' )
63
+ log ( :info , 'command execution threads shutdown, agent exiting now' )
65
64
end
66
65
end
67
66
68
67
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 } " )
71
70
end
72
-
71
+
73
72
def expand_conf_path ( key )
74
73
tmp = InstanceAgent ::Config . config [ key . to_sym ]
75
74
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)
78
77
def read_config
79
78
default_config = File . join ( @app_root_folder , "conf.yml" )
80
79
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" ) } )
82
81
InstanceAgent ::Config . load_config
83
82
84
83
expand_conf_path ( :root_dir )
@@ -89,23 +88,13 @@ def read_config
89
88
90
89
def with_error_handling
91
90
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 )
102
91
rescue SocketError => e
103
92
log ( :info , "#{ description } : failed to run as the connection failed! #{ e . class } - #{ e . message } - #{ e . backtrace . join ( "\n " ) } " )
104
93
sleep InstanceAgent ::Config . config [ :wait_after_connection_problem ]
105
94
rescue Exception => e
106
95
if ( e . message . to_s . match ( /throttle/i ) || e . message . to_s . match ( /rateexceeded/i ) rescue false )
107
96
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 ]
109
98
else
110
99
log ( :error , "#{ description } : error during start or run: #{ e . class } - #{ e . message } - #{ e . backtrace . join ( "\n " ) } " )
111
100
sleep 5
0 commit comments