#!/bin/bash # Init file for codedeploy-agent # # chkconfig: 2345 98 02 # description: codedeploy-agent processes the deployments created by AWS CodeDeploy and installs \ # the deployment artifacts on to this instance. ### BEGIN INIT INFO # Provides: codedeploy-agent # Required-Start: $all # Required-Stop: $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: AWS CodeDeploy Host Agent # Description: codedeploy-agent processes the deployments created by AWS CodeDeploy and installs # the deployment artifacts on to this instance. ### END INIT INFO COMMAND=$1 RETVAL=0 [ -f /etc/profile ] && [ "`stat --format '%U %G' /etc/profile`" == "root root" ] && source /etc/profile prog="codedeploy-agent" # Modify the following CODEDEPLOY_USER variable to run the codedeploy process as a non-root user # Note: You also need to chown /opt/codedeploy /var/log/aws CODEDEPLOY_USER="" AGENT_ROOT="/opt/codedeploy-agent/" INSTALLER="/opt/codedeploy-agent/bin/install" BIN="/opt/codedeploy-agent/bin/codedeploy-agent" start() { echo -n $"Starting $prog:" cd $AGENT_ROOT if [ $CODEDEPLOY_USER ]; then nohup sudo -i -u $CODEDEPLOY_USER $BIN start >/dev/null &1 # Try to start the server else nohup $BIN start >/dev/null &1 # Try to start the server fi exit $? } stop() { echo -n $"Stopping $prog:" cd $AGENT_ROOT if [ $CODEDEPLOY_USER ]; then nohup sudo -i -u $CODEDEPLOY_USER $BIN stop >/dev/null &1 # Try to stop the server else nohup $BIN stop >/dev/null &1 # Try to stop the server fi exit $? } restart() { echo -n $"Restarting $prog:" cd $AGENT_ROOT if [ $CODEDEPLOY_USER ]; then nohup sudo -i -u $CODEDEPLOY_USER $BIN restart >/dev/null &1 # Try to restart the server else nohup $BIN restart >/dev/null &1 # Try to restart the server fi exit $? } status() { cd $AGENT_ROOT if [ $CODEDEPLOY_USER ]; then sudo -i -u $CODEDEPLOY_USER $BIN status # Status of the server else $BIN status # Status of the server fi exit $? } update() { echo -n $"Updating $prog:" cd $AGENT_ROOT $INSTALLER auto #Update the agent } case "$COMMAND" in start) start ;; start-no-update) start ;; start-with-update) update start ;; stop) stop ;; restart) restart ;; force-reload) stop start ;; status) status ;; *) echo $"Usage: $0 {start|stop|status|restart}" esac