Skip to content

Commit f9a4fa6

Browse files
committed
add uwsgi startup script with watcher for development
1 parent b461976 commit f9a4fa6

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

Diff for: Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ RUN \
1717
'libcap-dev (>= 1:2.66)' \
1818
'libpcre3-dev (>= 2:8.39)' \
1919
'uwsgi-core (>= 2.0.21)' \
20-
'uwsgi-src (>= 2.0.21)'
20+
'uwsgi-src (>= 2.0.21)' \
21+
'inotify-tools (>= 3.22.6.0)'
2122

2223
/usr/bin/uwsgi --build-plugin "/usr/src/uwsgi/plugins/psgi"
2324
EOT
@@ -56,4 +57,5 @@ EOT
5657
COPY --from=build-uwsgi /psgi_plugin.so /usr/lib/uwsgi/plugins/psgi_plugin.so
5758
COPY --from=build-perl /usr/local/lib/perl5 /usr/local/lib/perl5
5859
COPY --from=build-perl /usr/local/bin /usr/local/bin
59-
COPY wait-for-it.sh /
60+
COPY watcher.sh uwsgi.sh wait-for-it.sh /
61+
COPY uwsgi.ini /etc/uwsgi.ini

Diff for: uwsgi.ini

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[uwsgi]
2+
master = true
3+
workers = 20
4+
early-psgi = true
5+
perl-no-die-catch = true
6+
disable-logging = true

Diff for: uwsgi.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
script_dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
4+
pid="$$"
5+
uwsgi_ini="/etc/uwsgi.ini"
6+
7+
if [[ "$PLACK_ENV" == "development" ]]; then
8+
if [[ -e '/etc/uwsgi-development.ini' ]]; then
9+
uwsgi_ini="/etc/uwsgi-development.ini"
10+
fi
11+
(
12+
set -m
13+
"$script_dir/watcher.sh" "$pid" lib *.conf &
14+
)
15+
fi
16+
17+
exec /usr/bin/uwsgi \
18+
--plugins psgi \
19+
--http-socket-modifier1 5 \
20+
--ini /etc/uwsgi.ini \
21+
"$@" \
22+
--psgi app.psgi

Diff for: watcher.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
pid="$1"
6+
shift
7+
8+
inotifywait --event create --event delete --event modify --event move \
9+
-m --format '%w%f' -r "$@" | \
10+
while read modify; do
11+
printf '%s\n' "Detected change to $modify, reloading uWSGI..."
12+
kill -HUP "$pid"
13+
done

0 commit comments

Comments
 (0)