Skip to content

Commit 9bb4d2c

Browse files
author
Gao Han
committed
Remove hard dependency on Ruby2.0 and add support for 2.x
1 parent f2d8cba commit 9bb4d2c

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

bin/codedeploy-agent

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/ruby2.0
2-
31
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
42
# have this method, so we add it so we get resolved symlinks
53
# and compatibility
@@ -16,7 +14,7 @@ end
1614
# This is required so that the agent can run without requiring an init script
1715
# if installed as a gem
1816

19-
agent_dir = "/opt/codedeploy-agent"
17+
agent_dir = File.join(File.dirname(__FILE__), "..")
2018
$:.unshift "#{agent_dir}/lib"
2119

2220
require 'instance_agent'
@@ -26,9 +24,15 @@ include GLI::App
2624

2725
program_desc 'AWS CodeDeploy Agent'
2826

27+
conf_default_dir = "/etc/codedeploy-agent/conf/codedeployagent.yml"
28+
conf_repo_dir = "#{agent_dir}/conf/codedeployagent.yml"
2929
desc 'Path to agent config file'
30-
default_value '/etc/codedeploy-agent/conf/codedeployagent.yml'
31-
arg_name '/etc/codedeploy-agent/conf/codedeployagent.yml'
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"
3236
flag [:config_file,:config_file]
3337

3438
desc 'start the AWS CodeDeploy agent'

bin/start-wrapper

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env ruby
2+
3+
arg = ARGV[0]
4+
ruby_versions = ["2.3", "2.2", "2.1", "2.0"]
5+
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}
6+
left_bound = '2.0.0'.split('.').map{|s|s.to_i}
7+
right_bound = '2.3.1'.split('.').map{|s|s.to_i}
8+
9+
if (actual_ruby_version <=> left_bound) > -1 && (actual_ruby_version <=> right_bound) < 1
10+
exec("ruby #{File.join(File.expand_path(File.dirname(__FILE__)), "/codedeploy-agent")} #{arg}")
11+
end
12+
13+
ruby_versions.each do |i|
14+
ruby_dir = "/usr/bin/ruby#{i}"
15+
if File.file?(ruby_dir)
16+
exec("#{ruby_dir} #{File.join(File.expand_path(File.dirname(__FILE__)), "/codedeploy-agent")} #{arg}")
17+
end
18+
end
19+
20+
puts "No supported ruby version found. Code Deploy Host Agent suuports Ruby version of 2.0.x to 2.3.x."
21+
exit(1)

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
USER=""
2828
AGENT_ROOT="/opt/codedeploy-agent/"
2929
INSTALLER="/opt/codedeploy-agent/bin/install"
30-
BIN="/opt/codedeploy-agent/bin/codedeploy-agent"
30+
BIN="/opt/codedeploy-agent/bin/start-wrapper"
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/sh -a -c '[ -f /etc/profile ] && source /etc/profile; /opt/codedeploy-agent/bin/codedeploy-agent start'
7-
ExecStop=/opt/codedeploy-agent/bin/codedeploy-agent stop
6+
ExecStart=/bin/sh -a -c '[ -f /etc/profile ] && source /etc/profile; /opt/codedeploy-agent/bin/start-wrapper start'
7+
ExecStop=/opt/codedeploy-agent/bin/start-wrapper stop
88
RemainAfterExit=no
99
# Comment out the following line to run the agent as the codedeploy user
1010
# Note: The user must first exist on the system

0 commit comments

Comments
 (0)