2022-02-27 16:11:02 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-03-03 01:37:38 +01:00
|
|
|
pkg_dependencies="$pkg_dependencies uwsgi uwsgi-plugin-python3"
|
2022-02-27 16:11:02 +01:00
|
|
|
|
|
|
|
# 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 <<EOF
|
|
|
|
[Unit]
|
|
|
|
Description=%i uWSGI app
|
|
|
|
After=syslog.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
RuntimeDirectory=%i
|
|
|
|
ExecStart=/usr/bin/uwsgi \
|
|
|
|
--ini /etc/uwsgi/apps-available/%i.ini \
|
|
|
|
--socket /run/%i/app.socket \
|
|
|
|
--logto /var/log/uwsgi/%i/%i.log
|
|
|
|
User=%i
|
|
|
|
Group=www-data
|
|
|
|
Restart=always
|
|
|
|
RestartSec=10
|
|
|
|
KillSignal=SIGQUIT
|
|
|
|
Type=notify
|
|
|
|
StandardError=syslog
|
|
|
|
NotifyAccess=all
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
systemctl daemon-reload
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a dedicated uwsgi ini file to use with generic uwsgi service
|
|
|
|
#
|
|
|
|
# usage: ynh_add_uwsgi_service [--service=service] [--template=template]
|
|
|
|
# | arg: -s, --service= - Service name (optionnal, `$app` by default)
|
|
|
|
# | arg: -t, --template= - Name of template file (optionnal, this is 'systemd' by default, meaning `../conf/systemd.service` will be used as template)
|
|
|
|
#
|
|
|
|
# This will use a template in ../conf/uwsgi.ini
|
|
|
|
#
|
|
|
|
# Note that the service need to be started manually at the end of the installation.
|
|
|
|
# Generally you can start the service with this command:
|
|
|
|
# ynh_systemd_action --service_name "uwsgi-app@$service.service" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$service/$service.log"
|
|
|
|
#
|
|
|
|
|
|
|
|
# to interact with your service: `systemctl <action> 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"
|
|
|
|
}
|