Skip to content

Commit e41c9af

Browse files
authored
Merge pull request #22 from guardian/aa-start
add start script
2 parents 476d8ba + 9d868bb commit e41c9af

2 files changed

Lines changed: 61 additions & 8 deletions

File tree

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See [troubleshooting faq](TROUBLESHOOTING.md)
1313

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

16-
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`.
16+
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`.
1717

1818
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.
1919

@@ -71,10 +71,11 @@ dev-nginx COMMAND <OPTIONS>
7171
Available commands:
7272
- add-to-hosts-file
7373
- link-config
74-
- locate-nginx
75-
- restart-nginx
74+
- locate
75+
- restart
7676
- setup-app
7777
- setup-cert
78+
- start
7879
```
7980

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

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

98-
#### `locate-nginx`
99+
#### `locate`
99100

100101
```bash
101-
dev-nginx locate-nginx
102+
dev-nginx locate
102103
```
103104

104105
Locates the directory nginx is installed.
105106

106-
#### `restart-nginx`
107+
#### `start`
108+
```bash
109+
dev-nginx start
110+
```
111+
112+
Starts nginx. Will fail if currently running. Add `-g` to ignore if nginx is currently running.
113+
114+
#### `restart`
107115

108116
```bash
109-
dev-nginx restart-nginx
117+
dev-nginx restart
110118
```
111119

112120
Stops, if running, and starts nginx.

script/start

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# colours
6+
YELLOW='\033[1;33m'
7+
NC='\033[0m' # no colour - reset console colour
8+
9+
GRACEFUL=false
10+
11+
function printHelp() {
12+
echo "Starts nginx. Will fail if nginx is already running."
13+
echo " Flags:"
14+
echo " -g | --graceful ignore nginx if it's already running"
15+
echo " -h | --help print this message"
16+
exit 0
17+
}
18+
19+
while test $# -gt 0; do
20+
case "$1" in
21+
-g|--graceful)
22+
GRACEFUL=true
23+
shift
24+
;;
25+
-h|--help)
26+
printHelp
27+
shift
28+
;;
29+
*)
30+
break
31+
;;
32+
esac
33+
done
34+
35+
if pgrep 'nginx' > /dev/null; then
36+
if [ "$GRACEFUL" = true ] ; then
37+
exit 0
38+
else
39+
echo -e "Error: nginx already running. Did you mean ${YELLOW}dev-nginx restart${NC} or ${YELLOW}dev-nginx start -g${NC}?"
40+
exit 1
41+
fi
42+
else
43+
echo -e "${YELLOW}Starting nginx. This requires sudo access.${NC}"
44+
sudo nginx
45+
fi

0 commit comments

Comments
 (0)