#!/bin/bash pkg_dependencies="$pkg_dependencies uwsgi uwsgi-plugin-python3" # 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 --message="You need to add uwsgi (and appropriate plugin) as a dependency" cat > /etc/systemd/system/uwsgi-app@.service < uwsgi-app@app` ynh_add_uwsgi_service () { # Declare an array to define the options of this helper. local legacy_args=st local -A args_array=([s]=service= [t]=template=) local service local template # Manage arguments with getopts ynh_handle_getopts_args "$@" service="${service:-$app}" template="${template:-uwsgi.ini}" 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 "$service" || ynh_die --message="It wasn't possible to add user $service to group www-data" ynh_add_config --template="$YNH_APP_BASEDIR/conf/$template" --destination="/etc/uwsgi/apps-available/$service.ini" chown $service:root "/etc/uwsgi/apps-available/$service.ini" # make sure the folder for logs exists and set authorizations mkdir -p /var/log/uwsgi/$service chown $service:root /var/log/uwsgi/$service chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$service # Setup specific Systemd rules if necessary test -e ../conf/uwsgi-app@override.service && \ mkdir /etc/systemd/system/uwsgi-app@$service.service.d && \ cp ../conf/uwsgi-app@override.service /etc/systemd/system/uwsgi-app@$service.service.d/override.conf systemctl enable "uwsgi-app@$service.service" --quiet systemctl daemon-reload # Add as a service yunohost service add "uwsgi-app@$service" --log "/var/log/uwsgi/$service/$service.log" } # Remove the dedicated uwsgi ini file # # usage: ynh_remove_uwsgi_service [--service=service] # | arg: -s, --service= - Service name (optionnal, $app by default) # ynh_remove_uwsgi_service () { # Declare an array to define the options of this helper. local legacy_args=s local -A args_array=([s]=service=) local service # Manage arguments with getopts ynh_handle_getopts_args "$@" local service="${service:-$app}" local finaluwsgiini="/etc/uwsgi/apps-available/$service.ini" if [ -e "$finaluwsgiini" ]; then yunohost service remove "uwsgi-app@$service" systemctl stop "uwsgi-app@$service.service" systemctl disable "uwsgi-app@$service.service" --quiet ynh_secure_remove --file="$finaluwsgiini" ynh_secure_remove --file="/var/log/uwsgi/$service" ynh_secure_remove --file="/etc/systemd/system/uwsgi-app@$service.service.d" fi } # Restore the dedicated uwsgi config # Should be used in restore script # # usage: ynh_restore_uwsgi_service [--service=service] # | arg: -s, --service= - Service name (optionnal, $app by default) ynh_restore_uwsgi_service () { # Declare an array to define the options of this helper. local legacy_args=s local -A args_array=([s]=service=) local service # Manage arguments with getopts ynh_handle_getopts_args "$@" service="${service:-$app}" ynh_check_global_uwsgi_config systemctl enable "uwsgi-app@$service" --quiet yunohost service add "uwsgi-app@$service" --log "/var/log/uwsgi/$service/$service.log" }