From e3458314873c9dfa7d33fc07376b6bf93f73e1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Wed, 5 Sep 2018 20:43:08 +0200 Subject: [PATCH] Update uwsgi helper --- conf/uwsgi-app@.service | 7 ++----- conf/uwsgi-app@.socket | 11 +++++++++++ scripts/_common.sh | 38 ++++++++++++++++++++------------------ scripts/install | 14 +++++++------- scripts/upgrade | 2 +- 5 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 conf/uwsgi-app@.socket diff --git a/conf/uwsgi-app@.service b/conf/uwsgi-app@.service index 888994d..6f630e8 100644 --- a/conf/uwsgi-app@.service +++ b/conf/uwsgi-app@.service @@ -1,3 +1,4 @@ + [Unit] Description=%i uWSGI app After=syslog.target @@ -6,8 +7,7 @@ After=syslog.target ExecStart=/usr/bin/uwsgi \ --ini /etc/uwsgi/apps-available/%i.ini \ --socket /var/run/uwsgi/%i.socket \ - --chmod-socket=775 \ - --logto /var/log/uwsgi/app/%i + --logto /var/log/uwsgi/%i/%i.log User=%i Group=www-data Restart=on-failure @@ -15,6 +15,3 @@ KillSignal=SIGQUIT Type=notify StandardError=syslog NotifyAccess=all - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/conf/uwsgi-app@.socket b/conf/uwsgi-app@.socket new file mode 100644 index 0000000..0975e29 --- /dev/null +++ b/conf/uwsgi-app@.socket @@ -0,0 +1,11 @@ +[Unit] +Description=Socket for uWSGI app %i + +[Socket] +ListenStream=/var/run/uwsgi/%i.socket +SocketUser=%i +SocketGroup=www-data +SocketMode=0775 + +[Install] +WantedBy=sockets.target diff --git a/scripts/_common.sh b/scripts/_common.sh index 549e30a..a2f8cdc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,19 +1,15 @@ #!/bin/bash +# Check if system wide templates are available and correcly configured +# +# usage: ynh_check_global_uwsgi_config ynh_check_global_uwsgi_config () { uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency" + cp ../conf/uwsgi-app@.socket /etc/systemd/system/uwsgi-app@.socket cp ../conf/uwsgi-app@.service /etc/systemd/system/uwsgi-app@.service - # make sure the folder for sockets exists and set authorizations - mkdir -p /var/run/uwsgi/ - chown root:www-data /var/run/uwsgi/ - chmod -R 775 /var/run/uwsgi/ - - # make sure the folder for logs exists and set authorizations - mkdir -p /var/log/uwsgi/app/ - chown root:www-data /var/log/uwsgi/app/ - chmod -R 775 /var/log/uwsgi/app/ + systemctl daemon-reload } # Create a dedicated uwsgi ini file to use with generic uwsgi service @@ -28,7 +24,7 @@ ynh_check_global_uwsgi_config () { # __PATH__ by $path_url # __FINALPATH__ by $final_path # -# usage: ynh_add_systemd_config +# usage: ynh_add_uwsgi_service # # to interact with your service: `systemctl uwsgi-app@app` ynh_add_uwsgi_service () { @@ -54,26 +50,32 @@ ynh_add_uwsgi_service () { fi ynh_store_file_checksum "$finaluwsgiini" - chown $app "$finaluwsgiini" + chown $app:root "$finaluwsgiini" + + # make sure the folder for logs exists and set authorizations + mkdir -p /var/log/uwsgi/$app + chown $app:root /var/log/uwsgi/$app + chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app systemctl daemon-reload - systemctl enable "uwsgi-app@$app.service" + systemctl enable "uwsgi-app@$app.socket" + systemctl start "uwsgi-app@$app.socket" # Add as a service - yunohost service add "uwsgi-app@$app.service" --log "/var/log/uwsgi/app/$app" + yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" } # Remove the dedicated uwsgi ini file # -# usage: ynh_remove_systemd_config +# usage: ynh_remove_uwsgi_service ynh_remove_uwsgi_service () { finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" if [ -e "$finaluwsgiini" ]; then - systemctl stop "uwsgi-app@$app.service" - systemctl disable "uwsgi-app@$app.service" - yunohost service remove "uwsgi-app@$app.service" + systemctl stop "uwsgi-app@$app.socket" + systemctl disable "uwsgi-app@$app.socket" + yunohost service remove "uwsgi-app@$app" ynh_secure_remove "$finaluwsgiini" - ynh_secure_remove "/var/log/uwsgi/app/$app" + ynh_secure_remove "/var/log/uwsgi/$app" fi } diff --git a/scripts/install b/scripts/install index d00f24d..208e2a6 100644 --- a/scripts/install +++ b/scripts/install @@ -113,12 +113,6 @@ ynh_system_user_create "$app" "$final_path" #================================================= # SPECIFIC SETUP -#================================================= -# SETUP UWSGI -#================================================= - -ynh_add_uwsgi_service - #================================================= # create config file syncserver.ini #================================================= @@ -176,6 +170,12 @@ virtualenv "$final_path/local" cp -r ../sources/page $final_path/syncserver/ (cd "$final_path/syncserver" && patch -p1 < $YNH_CWD/../sources/homepage.patch) || echo "Unable to apply patches" +#================================================= +# SETUP UWSGI +#================================================= + +ynh_add_uwsgi_service + #================================================= # GENERIC FINALIZATION #================================================= @@ -189,7 +189,7 @@ chmod u=rwX,g=rX,o= -R $final_path # SETUP LOGROTATE #================================================= -ynh_use_logrotate +ynh_use_logrotate /var/log/uwsgi/$app #================================================= # SETUP SSOWAT diff --git a/scripts/upgrade b/scripts/upgrade index ae7b1be..a37a945 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -197,7 +197,7 @@ chmod u=rwX,g=rX,o= -R $final_path # SETUP LOGROTATE #================================================= -ynh_use_logrotate +ynh_use_logrotate /var/log/uwsgi/$app --non-append #================================================= # SETUP SSOWAT