diff --git a/init.d/codedeploy-agent b/init.d/codedeploy-agent index 33849406..dfd4eb4c 100755 --- a/init.d/codedeploy-agent +++ b/init.d/codedeploy-agent @@ -17,9 +17,7 @@ # the deployment artifacts on to this instance. ### END INIT INFO -# Source function library. -. /etc/rc.d/init.d/functions - +COMMAND=$1 RETVAL=0 [ -f /etc/profile ] && [ "`stat --format '%U %G' /etc/profile`" == "root root" ] && source /etc/profile @@ -33,7 +31,7 @@ start() { echo -n $"Starting $prog:" cd $AGENT_ROOT if [ $USER ]; then - daemon --user=$USER $BIN start >/dev/null &1 # Try to start the server + nohup sudo -i -u $USER $BIN start >/dev/null &1 # Try to start the server else nohup $BIN start >/dev/null &1 # Try to start the server fi @@ -44,7 +42,7 @@ stop() { echo -n $"Stopping $prog:" cd $AGENT_ROOT if [ $USER ]; then - daemon --user=$USER $BIN stop >/dev/null &1 # Try to stop the server + nohup sudo -i -u $USER $BIN stop >/dev/null &1 # Try to stop the server else nohup $BIN stop >/dev/null &1 # Try to stop the server fi @@ -55,7 +53,7 @@ restart() { echo -n $"Restarting $prog:" cd $AGENT_ROOT if [ $USER ]; then - daemon --user=$USER $BIN restart >/dev/null &1 # Try to restart the server + nohup sudo -i -u $USER $BIN restart >/dev/null &1 # Try to restart the server else nohup $BIN restart >/dev/null &1 # Try to restart the server fi @@ -65,7 +63,7 @@ restart() { status() { cd $AGENT_ROOT if [ $USER ]; then - daemon --user=$USER $BIN status # Status of the server + sudo -i -u $USER $BIN status # Status of the server else $BIN status # Status of the server fi @@ -75,14 +73,10 @@ status() { 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 +case "$COMMAND" in start) start ;; diff --git a/init.d/codedeploy-agent.service b/init.d/codedeploy-agent.service new file mode 100644 index 00000000..09be6a66 --- /dev/null +++ b/init.d/codedeploy-agent.service @@ -0,0 +1,12 @@ +[Unit] +Description=AWS CodeDeploy Host Agent + +[Service] +Type=forking +ExecStart=/opt/codedeploy-agent/bin/codedeploy-agent start +ExecStop=/opt/codedeploy-agent/bin/codedeploy-agent stop +User=codedeploy +RemainAfterExit=no + +[Install] +WantedBy=multi-user.target diff --git a/lib/instance_agent/platform/linux_util.rb b/lib/instance_agent/platform/linux_util.rb index e8f020d5..402f308d 100644 --- a/lib/instance_agent/platform/linux_util.rb +++ b/lib/instance_agent/platform/linux_util.rb @@ -28,7 +28,7 @@ def self.prepare_script_command(script, absolute_cmd_path) # command as the code deploy agent user absolute_cmd_path end - + def self.quit() # Send kill signal to parent and exit Process.kill('TERM', Process.ppid) diff --git a/lib/instance_agent/plugins/codedeploy/command_executor.rb b/lib/instance_agent/plugins/codedeploy/command_executor.rb index 3ef33f7b..78b37984 100644 --- a/lib/instance_agent/plugins/codedeploy/command_executor.rb +++ b/lib/instance_agent/plugins/codedeploy/command_executor.rb @@ -11,7 +11,7 @@ module InstanceAgent module Plugins module CodeDeployPlugin ARCHIVES_TO_RETAIN = 5 - + class CommandExecutor class << self attr_reader :command_methods