Skip to content

Commit

Permalink
Merge pull request #10 from metacpan/haarg/uwsgi-watcher-and-config
Browse files Browse the repository at this point in the history
add uwsgi startup script with watcher for development
  • Loading branch information
haarg authored Apr 28, 2024
2 parents b461976 + f9a4fa6 commit 36b5e7e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ RUN \
'libcap-dev (>= 1:2.66)' \
'libpcre3-dev (>= 2:8.39)' \
'uwsgi-core (>= 2.0.21)' \
'uwsgi-src (>= 2.0.21)'
'uwsgi-src (>= 2.0.21)' \
'inotify-tools (>= 3.22.6.0)'

/usr/bin/uwsgi --build-plugin "/usr/src/uwsgi/plugins/psgi"
EOT
Expand Down Expand Up @@ -56,4 +57,5 @@ EOT
COPY --from=build-uwsgi /psgi_plugin.so /usr/lib/uwsgi/plugins/psgi_plugin.so
COPY --from=build-perl /usr/local/lib/perl5 /usr/local/lib/perl5
COPY --from=build-perl /usr/local/bin /usr/local/bin
COPY wait-for-it.sh /
COPY watcher.sh uwsgi.sh wait-for-it.sh /
COPY uwsgi.ini /etc/uwsgi.ini
6 changes: 6 additions & 0 deletions uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[uwsgi]
master = true
workers = 20
early-psgi = true
perl-no-die-catch = true
disable-logging = true
22 changes: 22 additions & 0 deletions uwsgi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

script_dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
pid="$$"
uwsgi_ini="/etc/uwsgi.ini"

if [[ "$PLACK_ENV" == "development" ]]; then
if [[ -e '/etc/uwsgi-development.ini' ]]; then
uwsgi_ini="/etc/uwsgi-development.ini"
fi
(
set -m
"$script_dir/watcher.sh" "$pid" lib *.conf &
)
fi

exec /usr/bin/uwsgi \
--plugins psgi \
--http-socket-modifier1 5 \
--ini /etc/uwsgi.ini \
"$@" \
--psgi app.psgi
13 changes: 13 additions & 0 deletions watcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -euo pipefail

pid="$1"
shift

inotifywait --event create --event delete --event modify --event move \
-m --format '%w%f' -r "$@" | \
while read modify; do
printf '%s\n' "Detected change to $modify, reloading uWSGI..."
kill -HUP "$pid"
done

0 comments on commit 36b5e7e

Please sign in to comment.