Skip to content

Commit

Permalink
rename flag and add help output
Browse files Browse the repository at this point in the history
  • Loading branch information
akash1810 committed Sep 29, 2020
1 parent 7d70791 commit 9d868bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Locates the directory nginx is installed.
dev-nginx start
```

Starts nginx. Will fail if currently running. Add `-i` to ignore if nginx is currently running.
Starts nginx. Will fail if currently running. Add `-g` to ignore if nginx is currently running.

#### `restart`

Expand Down
26 changes: 19 additions & 7 deletions script/start
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ set -e
YELLOW='\033[1;33m'
NC='\033[0m' # no colour - reset console colour

IGNORE_IF_ALREADY_RUNNING=false
GRACEFUL=false

function printHelp() {
echo "Starts nginx. Will fail if nginx is already running."
echo " Flags:"
echo " -g | --graceful ignore nginx if it's already running"
echo " -h | --help print this message"
exit 0
}

while test $# -gt 0; do
case "$1" in
-i|--ignore-if-already-running)
IGNORE_IF_ALREADY_RUNNING=true
-g|--graceful)
GRACEFUL=true
shift
;;
-h|--help)
printHelp
shift
;;
*)
Expand All @@ -21,13 +33,13 @@ while test $# -gt 0; do
done

if pgrep 'nginx' > /dev/null; then
echo "nginx already running"
if [ "$IGNORE_IF_ALREADY_RUNNING" = false ] ; then
echo -e "Did you mean ${YELLOW}dev-nginx start -i${NC} or ${YELLOW}dev-nginx restart${NC}?"
if [ "$GRACEFUL" = true ] ; then
exit 0
else
echo -e "Error: nginx already running. Did you mean ${YELLOW}dev-nginx restart${NC} or ${YELLOW}dev-nginx start -g${NC}?"
exit 1
fi
else
echo -e "${YELLOW}Starting nginx. This requires sudo access.${NC}"
sudo nginx
fi

0 comments on commit 9d868bb

Please sign in to comment.