Skip to content

Instantly share code, notes, and snippets.

@joaoneto
Last active December 22, 2015 15:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joaoneto/6491201 to your computer and use it in GitHub Desktop.
Save joaoneto/6491201 to your computer and use it in GitHub Desktop.
Start services, if they are not running
#!/bin/bash
EXITCODE="0"
SERVICES=(
"memcached &"
"mongod &"
"redis-server &"
"neo4j start"
"elasticsearch"
)
check_service() {
local pid=$(pgrep -f "${1%% *}")
echo $pid
}
start_service() {
eval $1 > /dev/null
if [[ $? -ne "0" ]]
then
EXITCODE="1"
echo -en "\r\033[0;31m ✗\e[0m Error starting service: ${SERVICES[$i]%% *}"
fi
}
for ((i = 0; i < ${#SERVICES[@]}; i++))
do
unset EXEC
if [[ -z $(check_service "${SERVICES[$i]}") ]]
then
echo -en "\033[0;31m ✗\033[0m ${SERVICES[$i]%% *}"
EXEC=$(start_service "${SERVICES[$i]}")
if [[ -z $EXEC ]]
then
echo -en "\r\033[0;32m ✓\033[0m ${SERVICES[$i]%% *}\n"
else
echo -en "$EXEC\n"
fi
else
echo -e "\033[0;32m ✓\033[0m ${SERVICES[$i]%% *}"
fi
done
exit $EXITCODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment