Skip to content

Instantly share code, notes, and snippets.

@alertor
Forked from joaoneto/start_services.sh
Created July 4, 2014 15:08
Show Gist options
  • Save alertor/520dc963ee0059685c04 to your computer and use it in GitHub Desktop.
Save alertor/520dc963ee0059685c04 to your computer and use it in GitHub Desktop.
#!/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