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

fully use socket activation

This commit is contained in:
Jean-Baptiste Holcroft 2017-11-21 13:09:12 +01:00
parent ee63b07215
commit fce38ffb8d
9 changed files with 31 additions and 50 deletions

View file

@ -8,7 +8,7 @@ ExecStart=/usr/bin/uwsgi \
--socket /var/run/uwsgi/%i.socket \
--logto /var/log/uwsgi/app/%i
User=%i
Group=uwsgi
Group=www-data
Restart=on-failure
KillSignal=SIGQUIT
Type=notify

View file

@ -4,8 +4,8 @@ Description=Socket for uWSGI app %i
[Socket]
ListenStream=/var/run/uwsgi/%i.socket
SocketUser=%i
SocketGroup=uwsgi
SocketMode=0660
SocketGroup=www-data
SocketMode=0775
[Install]
WantedBy=sockets.target

View file

@ -7,7 +7,6 @@ virtualenv = __FINALPATH__/venv
wsgi-file = __FINALPATH__/venv/lib/python2.7/site-packages/weblate/wsgi.py
# Needed for OAuth/OpenID
buffer-size = 8192
chmod-socket = 666
# Increase number of workers for heavily loaded sites
#workers = 6
# Needed for background processing

View file

@ -3,26 +3,25 @@
current_version="2.17.1"
ynh_check_global_uwsgi_config () {
uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency"
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
# 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/
}
# Create a dedicated uwsgi ini file to use with generic uwsgi service
@ -37,14 +36,15 @@ ynh_check_global_uwsgi_config () {
# __FINALPATH__ by $final_path
#
# usage: ynh_add_systemd_config
ynh_add_uwsgi_config () {
ynh_add_uwsgi_service () {
ynh_check_global_uwsgi_config
usermod --append --groups uwsgi "$app" || ynh_die "It wasn't possible to add user $app to group uwsgi"
# www-data group is needed since it is this nginx who will start the service
usermod --append --groups www-data "$app" || ynh_die "It wasn't possible to add user $app to group www-data"
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
ynh_backup_if_checksum_is_different "$finaluwsgiini"
sudo cp ../conf/uwsgi.ini "$finaluwsgiini"
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
@ -57,22 +57,23 @@ ynh_add_uwsgi_config () {
ynh_store_file_checksum "$finaluwsgiini"
chown root: "$finaluwsgiini"
systemctl enable "uwsgi-app@$app.service"
systemctl enable "uwsgi-app@$app.socket"
systemctl start "uwsgi-app@$app.socket"
systemctl daemon-reload
# Add as a service
yunohost service add "uwsgi-app@$app.service" --log "/var/run/uwsgi/$app.socket"
yunohost service add "uwsgi-app@$app.socket" --log "/var/log/uwsgi/app/$app"
}
# Remove the dedicated uwsgi ini file
#
# usage: ynh_remove_systemd_config
ynh_remove_uwsgi_config () {
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.socket"
ynh_secure_remove "$finaluwsgiini"
fi
@ -107,7 +108,7 @@ ynh_check_if_checksum_is_different() {
local checksum_value=$(ynh_app_setting_get $app $checksum_setting_name)
local check=0
if ! echo "$checksum_value $file" | sudo md5sum -c --status
if ! echo "$checksum_value $file" | md5sum -c --status
then # If the checksum is now different
check=1
fi

View file

@ -55,9 +55,3 @@ ynh_backup "db.sql"
#=================================================
ynh_backup "/etc/cron.d/$app"
#=================================================
# BACKUP THE UWSGI SERVICE
#=================================================
ynh_backup "/etc/uwsgi/apps-available/$app.ini"

View file

@ -177,7 +177,7 @@ EOF
# SPECIFIC SETUP uwsgi
#=================================================
ynh_add_uwsgi_config
ynh_add_uwsgi_service
#=================================================
# PIP INSTALLATION

View file

@ -58,7 +58,7 @@ ynh_secure_remove "/etc/cron.d/$app"
# REMOVE uwsgi and systemd files
#=================================================
ynh_remove_uwsgi_config
ynh_remove_uwsgi_service
#=================================================
# GENERIC FINALIZATION

View file

@ -90,17 +90,7 @@ ynh_psql_execute_file_as_root ./db.sql "$db_name"
# RESTORE THE 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 "uwsgi-app@$app.service"
ynh_add_uwsgi_service
#=================================================
# RESTORE THE CRON FILE

View file

@ -117,10 +117,7 @@ chsh --shell /bin/bash "$app"
# SPECIFIC SETUP uwsgi
#=================================================
ynh_add_uwsgi_config
# Add weblate as a service
yunohost service add "uwsgi-app@$app.service"
ynh_add_uwsgi_service
#=================================================
# PIP INSTALLATION