diff --git a/conf/nginx.conf b/conf/nginx.conf index ac13a2b..96cad12 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -8,7 +8,7 @@ location __PATH__ { uwsgi_read_timeout 3600; uwsgi_param SCRIPT_NAME __PATH__; uwsgi_modifier1 30; - uwsgi_pass unix://__FINALPATH__/socket; + uwsgi_pass unix:///var/run/uwsgi/__NAME__.socket; # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; diff --git a/conf/uwsgi-app@.service b/conf/uwsgi-app@.service new file mode 100644 index 0000000..c6baff2 --- /dev/null +++ b/conf/uwsgi-app@.service @@ -0,0 +1,16 @@ +[Unit] +Description=%i uWSGI app +After=syslog.target + +[Service] +ExecStart=/usr/bin/uwsgi \ + --ini /etc/uwsgi/apps-available/%i.ini \ + --socket /var/run/uwsgi/%i.socket \ + --logto /var/log/uwsgi/app/%i +User=%i +Group=uwsgi +Restart=on-failure +KillSignal=SIGQUIT +Type=notify +StandardError=syslog +NotifyAccess=all diff --git a/conf/uwsgi-app@.socket b/conf/uwsgi-app@.socket new file mode 100644 index 0000000..9b24b9d --- /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=uwsgi +SocketMode=0660 + +[Install] +WantedBy=sockets.target diff --git a/conf/uwsgi.ini b/conf/uwsgi.ini index 0cf4778..6ad64d2 100644 --- a/conf/uwsgi.ini +++ b/conf/uwsgi.ini @@ -2,10 +2,9 @@ plugins = python master = true protocol = uwsgi -socket = __FINALPATH__/socket +socket = /var/run/uwsgi/__APP__.socket virtualenv = __FINALPATH__/venv wsgi-file = __FINALPATH__/venv/lib/python2.7/site-packages/weblate/wsgi.py -python-path = __FINALPATH__/venv # Needed for OAuth/OpenID buffer-size = 8192 chmod-socket = 666 diff --git a/conf/uwsgi_service b/conf/uwsgi_service deleted file mode 100644 index d5fabe9..0000000 --- a/conf/uwsgi_service +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=uWSGI instance for __NAME__ -Requires=network.target -After=network.target - -[Service] -User=__NAME__ -Group=__NAME__ -RemainAfterExit=yes -WorkingDirectory=__FINALPATH__ -ExecStart=/usr/bin/uwsgi \ - --ini __FINALPATH__/uwsgi.ini \ - --socket __FINALPATH__/socket -Restart=always -StandardError=syslog - -[Install] -WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json index 61f299e..f8a0ea7 100644 --- a/manifest.json +++ b/manifest.json @@ -8,7 +8,7 @@ "description": { "en": "A translation platform using Git and Python" }, - "version": "2.17.1", + "version": "2.17.1-1", "url": "https://weblate.org", "license": "AGPL-3.0", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 16bd5ee..e2772f6 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -2,6 +2,83 @@ current_version="2.17.1" +ynh_check_global_uwsgi_config () { + if [ -f /etc/systemd/system/uwsgi-app@.service ]; + then + echo "Uwsgi generic file is already installed" + else + cp ../conf/uwsgi-app@.socket /etc/systemd/system/uwsgi-app@.socket + cp ../conf/uwsgi-app@.service /etc/systemd/system/uwsgi-app@.service + + # create uwsgi group + groupadd uwsgi + + # make sure the folder for sockets exists and set authorizations + mkdir -p /var/run/uwsgi/ + chown root:uwsgi /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:uwsgi /var/log/uwsgi/app/ + chmod -R 775 /var/log/uwsgi/app/ + fi +} + +# Create a dedicated uwsgi ini file to use with generic uwsgi service +# It will install generic uwsgi.socket and +# +# This will use a template in ../conf/uwsgi.ini +# and will replace the following keywords with +# global variables that should be defined before calling +# this helper : +# +# __APP__ by $app +# __FINALPATH__ by $final_path +# +# usage: ynh_add_systemd_config +ynh_add_uwsgi_config () { + ynh_check_global_uwsgi_config + + usermod --append --groups uwsgi "$app" || ynh_die "It wasn't possible to add user $app to group uwsgi" + + finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" + ynh_backup_if_checksum_is_different "$finaluwsgiini" + sudo cp ../conf/uwsgi.ini "$finaluwsgiini" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finaluwsgiini" + fi + if test -n "${app:-}"; then + ynh_replace_string "__APP__" "$app" "$finaluwsgiini" + fi + ynh_store_file_checksum "$finaluwsgiini" + + chown root: "$finaluwsgiini" + systemctl enable "uwsgi-app@$app.service" + systemctl daemon-reload + + # Add as a service + yunohost service add "uwsgi-app@$app.service" --log "/var/run/uwsgi/$app.socket" +} + +# Remove the dedicated uwsgi ini file +# +# usage: ynh_remove_systemd_config +ynh_remove_uwsgi_config () { + 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" + + ynh_secure_remove "$finaluwsgiini" + fi +} + + weblate_fill_settings() { settings="$1" diff --git a/scripts/backup b/scripts/backup index 8eef115..e86859f 100755 --- a/scripts/backup +++ b/scripts/backup @@ -50,12 +50,6 @@ ynh_backup "db.sql" #================================================= # SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - -ynh_backup "/etc/logrotate.d/$app" - #================================================= # BACKUP THE CRON FILE #================================================= @@ -63,7 +57,7 @@ ynh_backup "/etc/logrotate.d/$app" ynh_backup "/etc/cron.d/$app" #================================================= -# BACKUP THE SERVICE +# BACKUP THE UWSGI SERVICE #================================================= -ynh_backup "/etc/systemd/system/$app.service" +ynh_backup "/etc/uwsgi/apps-available/$app.ini" diff --git a/scripts/install b/scripts/install index 2be03c9..3746de2 100755 --- a/scripts/install +++ b/scripts/install @@ -168,7 +168,7 @@ ynh_replace_string "__GITHUBTOKEN__" "$github_token" "$final_path/.config/hub" cat < "$final_path/.bashrc" alias git=hub -PATH="$PATH:~/bin" +PATH="\$PATH:$final_path/bin" EOF #================================================= @@ -177,20 +177,7 @@ EOF # SPECIFIC SETUP uwsgi #================================================= -# Copy Files -cp ../conf/uwsgi.ini "$final_path/uwsgi.ini" -ynh_replace_string "__NAME__" "$app" "$final_path/uwsgi.ini" -ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/uwsgi.ini" - -cp ../conf/uwsgi_service "/etc/systemd/system/$app.service" -ynh_replace_string "__NAME__" "$app" "/etc/systemd/system/$app.service" -ynh_replace_string "__FINALPATH__" "$final_path" "/etc/systemd/system/$app.service" - -# Start service -systemctl enable "$app.service" - -# Add weblate as a service -yunohost service add "$app.service" --log "/var/log/$app/APP.log" +ynh_add_uwsgi_config #================================================= # PIP INSTALLATION @@ -262,13 +249,6 @@ ynh_store_file_checksum "$final_path/venv/lib/python2.7/site-packages/weblate/se # Set permissions to app files chown -R "$app": "$final_path" -#================================================= -# SETUP LOGROTATE -#================================================= - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate - #================================================= # SETUP SSOWAT #================================================= @@ -293,5 +273,5 @@ fi # RELOAD NGINX #================================================= -systemctl start "$app.service" +systemctl start "uwsgi-app@$app.service" systemctl reload nginx diff --git a/scripts/remove b/scripts/remove index acad42b..1b123ad 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,17 +17,6 @@ app=$YNH_APP_INSTANCE_NAME db_name=$(ynh_app_setting_get "$app" db_name) -#================================================= -# REMOVE SERVICE FROM ADMIN PANEL -#================================================= - -if yunohost service status | grep -q "$app" -then - echo "Remove $app service" - systemctl stop "$app.service" - yunohost service remove "$app.service" -fi - #================================================= # REMOVE THE PostgreSQL DATABASE #================================================= @@ -56,13 +45,6 @@ ynh_secure_remove "/var/www/$app" # Remove the dedicated nginx config ynh_remove_nginx_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= - -# Remove the app-specific logrotate config -ynh_remove_logrotate - #================================================= # SPECIFIC REMOVE #================================================= @@ -76,7 +58,7 @@ ynh_secure_remove "/etc/cron.d/$app" # REMOVE uwsgi and systemd files #================================================= -ynh_secure_remove "/etc/systemd/system/$app.service" +ynh_remove_uwsgi_config #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index e4df708..67a3b1b 100755 --- a/scripts/restore +++ b/scripts/restore @@ -90,14 +90,17 @@ ynh_psql_execute_file_as_root ./db.sql "$db_name" # RESTORE THE SERVICE #================================================= -ynh_restore_file "/etc/systemd/system/$app.service" -systemctl enable "$app.service" +ynh_restore_file "/etc/uwsgi/apps-available/$app.ini" + +ynh_check_global_uwsgi_config + +systemctl enable "uwsgi-app@$app.service" #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -yunohost service add "$app.service" --log "/var/log/$app/APP.log" +yunohost service add "uwsgi-app@$app.service" #================================================= # RESTORE THE CRON FILE @@ -105,18 +108,11 @@ yunohost service add "$app.service" --log "/var/log/$app/APP.log" ynh_restore_file "/etc/cron.d/$app" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file "/etc/logrotate.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX & uwsgi #================================================= +systemctl restart "uwsgi-app@$app.service" systemctl reload nginx -systemctl stop "$app.service" -systemctl start "$app.service" diff --git a/scripts/upgrade b/scripts/upgrade index 3d6a4f7..763c349 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -114,6 +114,13 @@ chsh --shell /bin/bash "$app" #================================================= # SPECIFIC UPGRADE #================================================= +# SPECIFIC SETUP uwsgi +#================================================= + +ynh_add_uwsgi_config + +# Add weblate as a service +yunohost service add "uwsgi-app@$app.service" #================================================= # PIP INSTALLATION @@ -205,13 +212,6 @@ fi # Recalculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" -#================================================= -# SETUP LOGROTATE -#================================================= - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate - #================================================= # GENERIC FINALIZATION #================================================= @@ -240,6 +240,5 @@ fi # RELOAD NGINX #================================================= -systemctl stop "$app.service" -systemctl start "$app.service" +systemctl restart "uwsgi-app@$app.service" systemctl reload nginx