1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00

Use uwsgi templates

This commit is contained in:
Jean-Baptiste Holcroft 2017-11-20 15:58:51 +01:00
parent 875b42f1a6
commit db4ffdf5f4
12 changed files with 128 additions and 92 deletions

View file

@ -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;

16
conf/uwsgi-app@.service Normal file
View file

@ -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

11
conf/uwsgi-app@.socket Normal file
View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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": {

View file

@ -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"

View file

@ -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"

View file

@ -168,7 +168,7 @@ ynh_replace_string "__GITHUBTOKEN__" "$github_token" "$final_path/.config/hub"
cat <<EOF > "$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

View file

@ -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

View file

@ -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"

View file

@ -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