-
-
Notifications
You must be signed in to change notification settings - Fork 884
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #361 from tobiasge/nginx-unit
Use Nginx Unit to serve the application
- Loading branch information
Showing
15 changed files
with
135 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import importlib.util | ||
import sys | ||
|
||
|
||
def _filename(f): | ||
return f.name | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
UNIT_CONFIG="${UNIT_CONFIG-/etc/unit/nginx-unit.json}" | ||
UNIT_SOCKET="/opt/unit/unit.sock" | ||
|
||
load_configuration() { | ||
MAX_WAIT=10 | ||
WAIT_COUNT=0 | ||
while [ ! -S $UNIT_SOCKET ]; do | ||
if [ $WAIT_COUNT -gte $MAX_WAIT ]; then | ||
echo "⚠️ No control socket found; configuration will not be loaded." | ||
return 1 | ||
fi | ||
|
||
WAIT_COUNT=$((WAIT_COUNT + 1)) | ||
echo "⏳ Waiting for control socket to be created... (${WAIT_COUNT}/${MAX_WAIT})" | ||
|
||
sleep 1 | ||
done | ||
|
||
# even when the control socket exists, it does not mean unit has finished initialisation | ||
# this curl call will get a reply once unit is fully launched | ||
curl --silent --output /dev/null --request GET --unix-socket $UNIT_SOCKET http://localhost/ | ||
|
||
echo "⚙️ Applying configuration from $UNIT_CONFIG"; | ||
|
||
RESP_CODE=$(curl \ | ||
--silent \ | ||
--output /dev/null \ | ||
--write-out '%{http_code}' \ | ||
--request PUT \ | ||
--data-binary "@${UNIT_CONFIG}" \ | ||
--unix-socket $UNIT_SOCKET \ | ||
http://localhost/config | ||
) | ||
if [ "$RESP_CODE" != "200" ]; then | ||
echo "⚠️ Could no load Unit configuration" | ||
kill "$(cat /opt/unit/unit.pid)" | ||
return 1 | ||
fi | ||
|
||
echo "✅ Unit configuration loaded successfully" | ||
} | ||
|
||
load_configuration & | ||
|
||
exec unitd \ | ||
--no-daemon \ | ||
--control unix:$UNIT_SOCKET \ | ||
--pid /opt/unit/unit.pid \ | ||
--log /dev/stdout \ | ||
--state /opt/unit/state/ \ | ||
--tmp /opt/unit/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"listeners": { | ||
"*:8080": { | ||
"pass": "routes" | ||
} | ||
}, | ||
|
||
"routes": [ | ||
{ | ||
"match": { | ||
"uri": "/static/*" | ||
}, | ||
"action": { | ||
"share": "/opt/netbox/netbox" | ||
} | ||
}, | ||
|
||
{ | ||
"action": { | ||
"pass": "applications/netbox" | ||
} | ||
} | ||
], | ||
|
||
"applications": { | ||
"netbox": { | ||
"type": "python 3", | ||
"path": "/opt/netbox/netbox/", | ||
"module": "netbox.wsgi", | ||
"home": "/opt/netbox/venv", | ||
"processes": { | ||
"max": 4, | ||
"spare": 1, | ||
"idle_timeout": 120 | ||
} | ||
} | ||
}, | ||
|
||
"access_log": "/dev/stdout" | ||
} |
Oops, something went wrong.