Skip to content

Commit 45f71af

Browse files
committed
Rename the codedeploy-agent-wrapper and move the agent functionality into the lib directory
1 parent cb0b324 commit 45f71af

File tree

5 files changed

+108
-108
lines changed

5 files changed

+108
-108
lines changed

bin/codedeploy-agent

Lines changed: 17 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,26 @@
1-
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
2-
# have this method, so we add it so we get resolved symlinks
3-
# and compatibility
4-
unless File.respond_to? :realpath
5-
class File #:nodoc:
6-
def self.realpath path
7-
return realpath(File.readlink(path)) if symlink?(path)
8-
path
9-
end
10-
end
11-
end
12-
13-
# Set the environment variables for ruby libs and vendor provided gems
14-
# This is required so that the agent can run without requiring an init script
15-
# if installed as a gem
16-
17-
agent_dir = File.join(File.dirname(__FILE__), "..")
18-
$:.unshift "#{agent_dir}/lib"
19-
20-
require 'instance_agent'
21-
require 'gli'
1+
#!/usr/bin/env ruby
222

23-
include GLI::App
3+
ruby_versions = ["2.3", "2.2", "2.1", "2.0"]
4+
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}
5+
left_bound = '2.0.0'.split('.').map{|s|s.to_i}
6+
right_bound = '2.3.1'.split('.').map{|s|s.to_i}
7+
ruby_bin = nil
248

25-
program_desc 'AWS CodeDeploy Agent'
26-
27-
conf_default_dir = "/etc/codedeploy-agent/conf/codedeployagent.yml"
28-
conf_repo_dir = "#{agent_dir}/conf/codedeployagent.yml"
29-
desc 'Path to agent config file'
30-
if File.file?(conf_default_dir)
31-
default_value conf_default_dir
9+
if (actual_ruby_version <=> left_bound) > -1 && (actual_ruby_version <=> right_bound) < 1
10+
ruby_bin = "ruby"
3211
else
33-
default_value conf_repo_dir
34-
end
35-
arg_name "conf_dir"
36-
flag [:config_file,:config_file]
37-
38-
desc 'start the AWS CodeDeploy agent'
39-
command :start do |c|
40-
c.action do |global_options,options,args|
41-
InstanceAgent::Runner::Master.start
42-
end
43-
end
44-
45-
desc 'stop the AWS CodeDeploy agent'
46-
command :stop do |c|
47-
c.action do |global_options,options,args|
48-
InstanceAgent::Runner::Master.stop
49-
if pid = InstanceAgent::Runner::Master.status
50-
raise 'AWS CodeDeploy agent is still running'
12+
ruby_versions.each do |i|
13+
ruby_dir = "/usr/bin/ruby#{i}"
14+
if File.file?(ruby_dir)
15+
ruby_bin = ruby_dir
16+
break
5117
end
5218
end
5319
end
5420

55-
desc 'restart the AWS CodeDeploy agent'
56-
command :restart do |c|
57-
c.action do |global_options,options,args|
58-
InstanceAgent::Runner::Master.restart
59-
end
60-
end
61-
62-
desc 'Report running status of the AWS CodeDeploy agent'
63-
command :status do |c|
64-
c.action do |global_options,options,args|
65-
if pid = InstanceAgent::Runner::Master.status
66-
puts "The AWS CodeDeploy agent is running as PID #{pid}"
67-
else
68-
raise 'No AWS CodeDeploy agent running'
69-
end
70-
end
71-
end
72-
73-
pre do |global,command,options,args|
74-
InstanceAgent::Config.config.keys.each do |config_key|
75-
InstanceAgent::Config.config(config_key => global[config_key]) if global[config_key].present?
76-
end
77-
78-
InstanceAgent::Platform.util = InstanceAgent::LinuxUtil
79-
80-
InstanceAgent::Config.load_config
81-
true
82-
end
83-
84-
on_error do |exception|
85-
true
21+
if ruby_bin
22+
exec("#{ruby_bin} #{File.join(File.expand_path(File.dirname(__FILE__)), "/codedeploy-agent")} #{ARGV.join(' ')}")
8623
end
8724

88-
exit run(ARGV)
25+
STDERR.puts "No supported ruby version found. Code Deploy Host Agent supports Ruby version of 2.0.x to 2.3.x."
26+
exit(1)

bin/codedeploy-agent-wrapper

Lines changed: 0 additions & 26 deletions
This file was deleted.

init.d/codedeploy-agent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ prog="codedeploy-agent"
2727
CODEDEPLOY_USER=""
2828
AGENT_ROOT="/opt/codedeploy-agent/"
2929
INSTALLER="/opt/codedeploy-agent/bin/install"
30-
BIN="/opt/codedeploy-agent/bin/codedeploy-agent-wrapper"
30+
BIN="/opt/codedeploy-agent/bin/codedeploy-agent"
3131

3232
start() {
3333
echo -n $"Starting $prog:"

init.d/codedeploy-agent.service

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Description=AWS CodeDeploy Host Agent
33

44
[Service]
55
Type=forking
6-
ExecStart=/bin/bash -a -c '[ -f /etc/profile ] && source /etc/profile; /opt/codedeploy-agent/bin/codedeploy-agent-wrapper start'
7-
ExecStop=/opt/codedeploy-agent/bin/codedeploy-agent-wrapper stop
6+
ExecStart=/bin/bash -a -c '[ -f /etc/profile ] && source /etc/profile; /opt/codedeploy-agent/bin/codedeploy-agent start'
7+
ExecStop=/opt/codedeploy-agent/bin/codedeploy-agent stop
88
RemainAfterExit=no
99
Restart=on-failure
1010

lib/codedeploy-agent.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
2+
# have this method, so we add it so we get resolved symlinks
3+
# and compatibility
4+
unless File.respond_to? :realpath
5+
class File #:nodoc:
6+
def self.realpath path
7+
return realpath(File.readlink(path)) if symlink?(path)
8+
path
9+
end
10+
end
11+
end
12+
13+
# Set the environment variables for ruby libs and vendor provided gems
14+
# This is required so that the agent can run without requiring an init script
15+
# if installed as a gem
16+
17+
agent_dir = "/opt/codedeploy-agent"
18+
$:.unshift "#{agent_dir}/lib"
19+
20+
require 'instance_agent'
21+
require 'gli'
22+
23+
include GLI::App
24+
25+
program_desc 'AWS CodeDeploy Agent'
26+
27+
conf_default_dir = "/etc/codedeploy-agent/conf/codedeployagent.yml"
28+
conf_repo_dir = "#{agent_dir}/conf/codedeployagent.yml"
29+
desc 'Path to agent config file'
30+
if File.file?(conf_default_dir)
31+
default_value conf_default_dir
32+
else
33+
default_value conf_repo_dir
34+
end
35+
arg_name "conf_dir"
36+
flag [:config_file,:config_file]
37+
38+
desc 'start the AWS CodeDeploy agent'
39+
command :start do |c|
40+
c.action do |global_options,options,args|
41+
InstanceAgent::Runner::Master.start
42+
end
43+
end
44+
45+
desc 'stop the AWS CodeDeploy agent'
46+
command :stop do |c|
47+
c.action do |global_options,options,args|
48+
InstanceAgent::Runner::Master.stop
49+
if pid = InstanceAgent::Runner::Master.status
50+
raise 'AWS CodeDeploy agent is still running'
51+
end
52+
end
53+
end
54+
55+
desc 'restart the AWS CodeDeploy agent'
56+
command :restart do |c|
57+
c.action do |global_options,options,args|
58+
InstanceAgent::Runner::Master.restart
59+
end
60+
end
61+
62+
desc 'Report running status of the AWS CodeDeploy agent'
63+
command :status do |c|
64+
c.action do |global_options,options,args|
65+
if pid = InstanceAgent::Runner::Master.status
66+
puts "The AWS CodeDeploy agent is running as PID #{pid}"
67+
else
68+
raise 'No AWS CodeDeploy agent running'
69+
end
70+
end
71+
end
72+
73+
pre do |global,command,options,args|
74+
InstanceAgent::Config.config.keys.each do |config_key|
75+
InstanceAgent::Config.config(config_key => global[config_key]) if global[config_key].present?
76+
end
77+
78+
InstanceAgent::Platform.util = InstanceAgent::LinuxUtil
79+
80+
InstanceAgent::Config.load_config
81+
true
82+
end
83+
84+
on_error do |exception|
85+
true
86+
end
87+
88+
exit run(ARGV)

0 commit comments

Comments
 (0)