0

I am deploying an app to AWS EC2 instance and I am using a config file in the .ebextensions folder to execute a bash script.

In the script I am detecting if a particular service is running, if it's not running, install the package using rpm.

#!/bin/bash

service --status-all | grep -q 'MyService'

if [ $? -ne 0 ];
then
    install my package
else
    do nothing
fi

But the script is not working and it always go to install my service again.

It is because

service --status-all

is returning nothing at all which confuses me! But after the deployment when I go to the EC2 instance and try out the script, it does work. Just that it does not work during deployment.

There should be at least some services running but empty?

Am I doing this correctly?

Steven Yong
  • 5,163
  • 6
  • 35
  • 56

1 Answers1

0

Figured out what's wrong, putting it here for for everyone's reference.

service --status-all 

works while in the bash prompt, but does not seem to return anything during my AWS EC2 deployment.

I have changed it to something like

if ps ax | grep -v grep | grep -q 'My Service' 

from here: http://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/

and it works perfectly.

Steven Yong
  • 5,163
  • 6
  • 35
  • 56