Rewrite uwsgi to use the helper
This commit is contained in:
@@ -1,2 +1,79 @@
|
||||
#!/bin/bash
|
||||
|
||||
ynh_check_global_uwsgi_config () {
|
||||
uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency"
|
||||
|
||||
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/
|
||||
}
|
||||
|
||||
# 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
|
||||
# __PATH__ by $path_url
|
||||
# __FINALPATH__ by $final_path
|
||||
#
|
||||
# usage: ynh_add_systemd_config
|
||||
#
|
||||
# to interact with your service: `systemctl <action> uwsgi-app@app`
|
||||
ynh_add_uwsgi_service () {
|
||||
ynh_check_global_uwsgi_config
|
||||
|
||||
# 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"
|
||||
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 "${path_url:-}"; then
|
||||
ynh_replace_string "__PATH__" "$path_url" "$finaluwsgiini"
|
||||
fi
|
||||
if test -n "${app:-}"; then
|
||||
ynh_replace_string "__APP__" "$app" "$finaluwsgiini"
|
||||
fi
|
||||
ynh_store_file_checksum "$finaluwsgiini"
|
||||
|
||||
chown root: "$finaluwsgiini"
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable "uwsgi-app@$app.service"
|
||||
|
||||
# Add as a service
|
||||
yunohost service add "uwsgi-app@$app.service" --log "/var/log/uwsgi/app/$app"
|
||||
}
|
||||
|
||||
# Remove the dedicated uwsgi ini file
|
||||
#
|
||||
# usage: ynh_remove_systemd_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"
|
||||
|
||||
ynh_secure_remove "$finaluwsgiini"
|
||||
ynh_secure_remove "/var/log/uwsgi/app/$app"
|
||||
fi
|
||||
}
|
||||
@@ -60,7 +60,8 @@ ynh_mysql_dump_db "$db_name" > db.sql
|
||||
ynh_backup "/etc/logrotate.d/$app"
|
||||
|
||||
#=================================================
|
||||
# BACKUP SYSTEMD
|
||||
# BACKUP THE UWSGI FILES
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/systemd/system/$app.service"
|
||||
ynh_backup "/etc/uwsgi/apps-available/$app.ini"
|
||||
ynh_backup "/etc/systemd/system/uwsgi-app@.service"
|
||||
@@ -114,10 +114,10 @@ ynh_system_user_create "$app" "$final_path"
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
# SETUP UWSGI
|
||||
#=================================================
|
||||
|
||||
ynh_add_systemd_config
|
||||
ynh_add_uwsgi_service
|
||||
|
||||
#=================================================
|
||||
# create config file syncserver.ini
|
||||
@@ -128,17 +128,19 @@ secret=$(ynh_string_random)
|
||||
ynh_app_setting_set "$app" secret "$secret"
|
||||
|
||||
# Copy Files
|
||||
cp ../conf/syncserver.ini "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__APP__" "$app" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__PATH__" "$path_url" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__NAME__" "$app" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__SECRET__" "$secret" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__APP__" "$app" "$finaluwsgiini"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$finaluwsgiini"
|
||||
ynh_replace_string "__PATH__" "$path_url" "$finaluwsgiini"
|
||||
ynh_replace_string "__NAME__" "$app" "$finaluwsgiini"
|
||||
ynh_replace_string "__FINALPATH__" "$final_path" "$finaluwsgiini"
|
||||
ynh_replace_string "__SECRET__" "$secret" "$finaluwsgiini"
|
||||
|
||||
ynh_replace_string "__DB_USER__" "$db_user" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__DB_USER__" "$db_user" "$finaluwsgiini"
|
||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "$finaluwsgiini"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "$finaluwsgiini"
|
||||
|
||||
rm "$final_path/syncserver.ini"
|
||||
ln -s "$finaluwsgiini" "$final_path/syncserver.ini"
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
@@ -183,12 +185,6 @@ virtualenv "$final_path/local"
|
||||
|
||||
ynh_use_logrotate
|
||||
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
#=================================================
|
||||
|
||||
yunohost service add "$app" -l /var/log/$app/$app.log
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
@@ -200,5 +196,5 @@ ynh_app_setting_set "$app" skipped_uris "/"
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl start "$app.service"
|
||||
systemctl start "uwsgi-app@$app.service"
|
||||
systemctl reload nginx
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
@@ -24,20 +23,10 @@ db_name=$app
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# STOP AND REMOVE SERVICE
|
||||
# REMOVE UWSGI
|
||||
#=================================================
|
||||
|
||||
ynh_remove_systemd_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE SERVICE FROM ADMIN PANEL
|
||||
#=================================================
|
||||
|
||||
if yunohost service status | grep -q "$app"
|
||||
then
|
||||
echo "Remove $app service"
|
||||
yunohost service remove "$app"
|
||||
fi
|
||||
ynh_remove_uwsgi_service
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
|
||||
@@ -85,18 +85,38 @@ ynh_system_user_create "$app"
|
||||
ynh_install_app_dependencies python-dev python-virtualenv \
|
||||
uwsgi uwsgi-plugin-python
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE UWSGI MECANICS
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/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/
|
||||
|
||||
#=================================================
|
||||
# RESTORE SERVICE
|
||||
#=================================================
|
||||
|
||||
usermod --append --groups www-data "$app"
|
||||
|
||||
ynh_restore_file "/etc/uwsgi/apps-available/$app.ini"
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable "uwsgi-app@$app.service"
|
||||
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
#=================================================
|
||||
|
||||
yunohost service add "$app" --log "/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# RESTORE SYSTEMD
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/systemd/system/$app.service"
|
||||
systemctl enable "$app.service"
|
||||
yunohost service add "uwsgi-app@$app.service" --log "/var/log/uwsgi/app/$app"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE LOGROTATE CONFIGURATION
|
||||
@@ -110,5 +130,5 @@ ynh_restore_file "/etc/logrotate.d/$app"
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
|
||||
systemctl start "$app.service"
|
||||
systemctl start "uwsgi-app@$app.service"
|
||||
systemctl reload nginx
|
||||
|
||||
@@ -63,7 +63,7 @@ if [ -e /opt/yunohost/ffsync ]; then
|
||||
ynh_secure_remove /var/log/ffsync.log
|
||||
ynh_secure_remove /opt/yunohost/ffsync
|
||||
|
||||
ynh_add_systemd_config
|
||||
yunohost service remove "$app"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
@@ -96,6 +96,12 @@ path_url=$(ynh_normalize_url_path "$path_url")
|
||||
ynh_install_app_dependencies python-dev python-virtualenv \
|
||||
uwsgi uwsgi-plugin-python
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP UWSGI
|
||||
#=================================================
|
||||
|
||||
ynh_add_uwsgi_service
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
@@ -136,17 +142,41 @@ ynh_system_user_create "$app"
|
||||
#=================================================
|
||||
|
||||
# Copy Files
|
||||
cp ../conf/syncserver.ini "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__APP__" "$app" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__PATH__" "$path_url" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__NAME__" "$app" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__SECRET__" "$secret" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__APP__" "$app" "$finaluwsgiini"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$finaluwsgiini"
|
||||
ynh_replace_string "__PATH__" "$path_url" "$finaluwsgiini"
|
||||
ynh_replace_string "__NAME__" "$app" "$finaluwsgiini"
|
||||
ynh_replace_string "__FINALPATH__" "$final_path" "$finaluwsgiini"
|
||||
ynh_replace_string "__SECRET__" "$secret" "$finaluwsgiini"
|
||||
|
||||
ynh_replace_string "__DB_USER__" "$db_user" "$finaluwsgiini"
|
||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "$finaluwsgiini"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "$finaluwsgiini"
|
||||
|
||||
rm "$final_path/syncserver.ini"
|
||||
ln -s "$finaluwsgiini" "$final_path/syncserver.ini"
|
||||
|
||||
#=================================================
|
||||
# pip installation
|
||||
#=================================================
|
||||
|
||||
virtualenv "$final_path/local"
|
||||
# Init virtualenv
|
||||
(
|
||||
set +o nounset
|
||||
source "$final_path/local/bin/activate"
|
||||
set -o nounset
|
||||
cd "$final_path"
|
||||
pip install --upgrade pip
|
||||
CFLAGS="-Wno-error -Wno-error=format-security" \
|
||||
ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" \
|
||||
pip install --requirement "$final_path/requirements.txt"
|
||||
|
||||
python "$final_path/setup.py" develop
|
||||
|
||||
touch "$final_path/local/COMPLETE"
|
||||
)
|
||||
|
||||
ynh_replace_string "__DB_USER__" "$db_user" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/syncserver.ini"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/syncserver.ini"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
@@ -162,12 +192,6 @@ ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/syncserver.ini"
|
||||
|
||||
ynh_use_logrotate
|
||||
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
#=================================================
|
||||
|
||||
yunohost service add "$app" -l /var/log/$app/$app.log
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
@@ -178,6 +202,5 @@ ynh_app_setting_set "$app" skipped_uris "/"
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl stop "$app.service"
|
||||
systemctl start "$app.service"
|
||||
systemctl start "uwsgi-app@$app.service"
|
||||
systemctl reload nginx
|
||||
|
||||
Reference in New Issue
Block a user