diff --git a/init.d/codedeploy-agent b/init.d/codedeploy-agent index 33849406..d4eadf42 100755 --- a/init.d/codedeploy-agent +++ b/init.d/codedeploy-agent @@ -17,14 +17,11 @@ # the deployment artifacts on to this instance. ### END INIT INFO -# Source function library. -. /etc/rc.d/init.d/functions RETVAL=0 [ -f /etc/profile ] && [ "`stat --format '%U %G' /etc/profile`" == "root root" ] && source /etc/profile prog="codedeploy-agent" -USER="" AGENT_ROOT="/opt/codedeploy-agent/" INSTALLER="/opt/codedeploy-agent/bin/install" BIN="/opt/codedeploy-agent/bin/codedeploy-agent" @@ -32,54 +29,34 @@ BIN="/opt/codedeploy-agent/bin/codedeploy-agent" start() { echo -n $"Starting $prog:" cd $AGENT_ROOT - if [ $USER ]; then - daemon --user=$USER $BIN start >/dev/null &1 # Try to start the server - else - nohup $BIN start >/dev/null &1 # Try to start the server - fi + nohup $BIN start >/dev/null &1 # Try to start the server exit $? } stop() { echo -n $"Stopping $prog:" cd $AGENT_ROOT - if [ $USER ]; then - daemon --user=$USER $BIN stop >/dev/null &1 # Try to stop the server - else - nohup $BIN stop >/dev/null &1 # Try to stop the server - fi + nohup $BIN stop >/dev/null &1 # Try to stop the server exit $? } restart() { echo -n $"Restarting $prog:" cd $AGENT_ROOT - if [ $USER ]; then - daemon --user=$USER $BIN restart >/dev/null &1 # Try to restart the server - else - nohup $BIN restart >/dev/null &1 # Try to restart the server - fi + nohup $BIN restart >/dev/null &1 # Try to restart the server exit $? } status() { cd $AGENT_ROOT - if [ $USER ]; then - daemon --user=$USER $BIN status # Status of the server - else - $BIN status # Status of the server - fi + $BIN status # Status of the server exit $? } update() { echo -n $"Updating $prog:" cd $AGENT_ROOT - if [ $USER ]; then - daemon --user=$USER sudo $INSTALLER auto #Update the agent - else - $INSTALLER auto #Update the agent - fi + $INSTALLER auto #Update the agent } case "$1" in diff --git a/lib/instance_agent/platform/linux_util.rb b/lib/instance_agent/platform/linux_util.rb index 272cabcd..cc25442e 100644 --- a/lib/instance_agent/platform/linux_util.rb +++ b/lib/instance_agent/platform/linux_util.rb @@ -8,25 +8,12 @@ def self.supported_oses() ['linux'] end - def self.prepare_script_command(script, absolute_cmd_path) - runas = !!script.runas - sudo = !!script.sudo - - if runas && sudo - return 'sudo su ' + script.runas + ' -c ' + absolute_cmd_path - end - - if runas && !sudo - return 'su ' + script.runas + ' -c ' + absolute_cmd_path + def self.prepare_script_command(script, absolute_path) + script_command = absolute_path + if(!script.runas.nil?) + script_command = 'su ' + script.runas + ' -c ' + absolute_path end - - if !runas && sudo - return 'sudo ' + absolute_cmd_path - end - - # If neither sudo or runas is specified, execute the - # command as the code deploy agent user - absolute_cmd_path + script_command end def self.quit() diff --git a/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb b/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb index b3d7d751..61a6b31e 100644 --- a/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb +++ b/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb @@ -60,7 +60,6 @@ def parse_hooks(hooks_hash) current_hook_scripts << InstanceAgent::Plugins::CodeDeployPlugin::ApplicationSpecification::ScriptInfo.new(script['location'].to_s.strip, { :runas => script.has_key?('runas') && !script['runas'].nil? ? script['runas'].to_s.strip : nil, - :sudo => script['sudo'], :timeout => script['timeout'] }) else @@ -141,4 +140,4 @@ def parse_context(context) end end end -end +end \ No newline at end of file diff --git a/lib/instance_agent/plugins/codedeploy/application_specification/script_info.rb b/lib/instance_agent/plugins/codedeploy/application_specification/script_info.rb index 95ce6354..526751b8 100644 --- a/lib/instance_agent/plugins/codedeploy/application_specification/script_info.rb +++ b/lib/instance_agent/plugins/codedeploy/application_specification/script_info.rb @@ -5,7 +5,7 @@ module ApplicationSpecification #Helper Class for storing data parsed from hook script maps class ScriptInfo - attr_reader :location, :runas, :sudo, :timeout + attr_reader :location, :runas, :timeout def initialize(location, opts = {}) location = location.to_s if(location.empty?) @@ -13,7 +13,6 @@ def initialize(location, opts = {}) end @location = location @runas = opts[:runas] - @sudo = opts[:sudo] @timeout = opts[:timeout] || 3600 @timeout = @timeout.to_i if(@timeout <= 0) @@ -25,4 +24,4 @@ def initialize(location, opts = {}) end end end -end +end \ No newline at end of file diff --git a/test/instance_agent/platform/linux_util_test.rb b/test/instance_agent/platform/linux_util_test.rb deleted file mode 100644 index c51c959b..00000000 --- a/test/instance_agent/platform/linux_util_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'test_helper' - -class LinuxUtilTest < InstanceAgentTestCase - context 'Testing building command with sudo' do - setup do - @script_mock = Struct.new :sudo, :runas - end - - should 'return command with sudo with runas user deploy' do - mock = @script_mock.new true, "deploy" - assert_equal 'sudo su deploy -c my_script.sh', - InstanceAgent::LinuxUtil.prepare_script_command(mock, "my_script.sh") - end - - should 'return command without sudo with runas user deploy' do - mock = @script_mock.new nil, "deploy" - assert_equal 'su deploy -c my_script.sh', - InstanceAgent::LinuxUtil.prepare_script_command(mock, "my_script.sh") - end - - should 'return command without sudo or runas user' do - mock = @script_mock.new nil, nil - assert_equal 'my_script.sh', - InstanceAgent::LinuxUtil.prepare_script_command(mock, "my_script.sh") - end - - should 'return command with sudo' do - mock = @script_mock.new true, nil - assert_equal 'sudo my_script.sh', - InstanceAgent::LinuxUtil.prepare_script_command(mock, "my_script.sh") - end - - end -end -