Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add uwsgi startup script with watcher for development #10

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading