Skip to content

Commit

Permalink
Merge pull request #22 from guardian/aa-start
Browse files Browse the repository at this point in the history
add start script
  • Loading branch information
akash1810 authored Sep 29, 2020
2 parents 476d8ba + 9d868bb commit e41c9af
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See [troubleshooting faq](TROUBLESHOOTING.md)

Installing and running dev-nginx will start an [nginx](https://nginx.org/en/) server instance locally on your machine.

This instance will use any `*.conf` files found locally within the directory `/nginx/servers` to generate a virtual server host to proxy requests to localhost. You can locate this directory with the command `dev-nginx locate-nginx`.
This instance will use any `*.conf` files found locally within the directory `/nginx/servers` to generate a virtual server host to proxy requests to localhost. You can locate this directory with the command `dev-nginx locate`.

Each project config should include http directives for proxy localhost ports and necessary SSL certificates. This is quite repetitive, so `dev-nginx` abstracts it away with the `setup-app` and `setup-cert` commands.

Expand Down Expand Up @@ -71,10 +71,11 @@ dev-nginx COMMAND <OPTIONS>
Available commands:
- add-to-hosts-file
- link-config
- locate-nginx
- restart-nginx
- locate
- restart
- setup-app
- setup-cert
- start
```

### Commands
Expand All @@ -93,20 +94,27 @@ If it does not already exist, adds an entry to `/etc/hosts` that resolves to `12
dev-nginx link-config /path/to/site.conf
```

Symlink an existing file into nginx configuration. You'll need to restart nginx to activate it (`dev-nginx restart-nginx`).
Symlink an existing file into nginx configuration. You'll need to restart nginx to activate it (`dev-nginx restart`).

#### `locate-nginx`
#### `locate`

```bash
dev-nginx locate-nginx
dev-nginx locate
```

Locates the directory nginx is installed.

#### `restart-nginx`
#### `start`
```bash
dev-nginx start
```

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

#### `restart`

```bash
dev-nginx restart-nginx
dev-nginx restart
```

Stops, if running, and starts nginx.
Expand Down
45 changes: 45 additions & 0 deletions script/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -e

# colours
YELLOW='\033[1;33m'
NC='\033[0m' # no colour - reset console colour

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
-g|--graceful)
GRACEFUL=true
shift
;;
-h|--help)
printHelp
shift
;;
*)
break
;;
esac
done

if pgrep 'nginx' > /dev/null; then
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 e41c9af

Please sign in to comment.