diff --git a/README.md b/README.md index 754637f..bbd6665 100644 --- a/README.md +++ b/README.md @@ -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. @@ -71,10 +71,11 @@ dev-nginx COMMAND Available commands: - add-to-hosts-file - link-config -- locate-nginx -- restart-nginx +- locate +- restart - setup-app - setup-cert +- start ``` ### Commands @@ -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. diff --git a/script/start b/script/start new file mode 100755 index 0000000..94477dd --- /dev/null +++ b/script/start @@ -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