Update uwsgi helper

pull/6/head
Josué Tille 6 years ago
parent b88c7adfec
commit e345831487

@ -1,3 +1,4 @@
[Unit] [Unit]
Description=%i uWSGI app Description=%i uWSGI app
After=syslog.target After=syslog.target
@ -6,8 +7,7 @@ After=syslog.target
ExecStart=/usr/bin/uwsgi \ ExecStart=/usr/bin/uwsgi \
--ini /etc/uwsgi/apps-available/%i.ini \ --ini /etc/uwsgi/apps-available/%i.ini \
--socket /var/run/uwsgi/%i.socket \ --socket /var/run/uwsgi/%i.socket \
--chmod-socket=775 \ --logto /var/log/uwsgi/%i/%i.log
--logto /var/log/uwsgi/app/%i
User=%i User=%i
Group=www-data Group=www-data
Restart=on-failure Restart=on-failure
@ -15,6 +15,3 @@ KillSignal=SIGQUIT
Type=notify Type=notify
StandardError=syslog StandardError=syslog
NotifyAccess=all NotifyAccess=all
[Install]
WantedBy=multi-user.target

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

@ -1,19 +1,15 @@
#!/bin/bash #!/bin/bash
# Check if system wide templates are available and correcly configured
#
# usage: ynh_check_global_uwsgi_config
ynh_check_global_uwsgi_config () { ynh_check_global_uwsgi_config () {
uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency" uwsgi --version || ynh_die "You need to add uwsgi (and appropriate plugin) as a dependency"
cp ../conf/uwsgi-app@.socket /etc/systemd/system/uwsgi-app@.socket
cp ../conf/uwsgi-app@.service /etc/systemd/system/uwsgi-app@.service cp ../conf/uwsgi-app@.service /etc/systemd/system/uwsgi-app@.service
# make sure the folder for sockets exists and set authorizations systemctl daemon-reload
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 # Create a dedicated uwsgi ini file to use with generic uwsgi service
@ -28,7 +24,7 @@ ynh_check_global_uwsgi_config () {
# __PATH__ by $path_url # __PATH__ by $path_url
# __FINALPATH__ by $final_path # __FINALPATH__ by $final_path
# #
# usage: ynh_add_systemd_config # usage: ynh_add_uwsgi_service
# #
# to interact with your service: `systemctl <action> uwsgi-app@app` # to interact with your service: `systemctl <action> uwsgi-app@app`
ynh_add_uwsgi_service () { ynh_add_uwsgi_service () {
@ -54,26 +50,32 @@ ynh_add_uwsgi_service () {
fi fi
ynh_store_file_checksum "$finaluwsgiini" ynh_store_file_checksum "$finaluwsgiini"
chown $app "$finaluwsgiini" chown $app:root "$finaluwsgiini"
# make sure the folder for logs exists and set authorizations
mkdir -p /var/log/uwsgi/$app
chown $app:root /var/log/uwsgi/$app
chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app
systemctl daemon-reload systemctl daemon-reload
systemctl enable "uwsgi-app@$app.service" systemctl enable "uwsgi-app@$app.socket"
systemctl start "uwsgi-app@$app.socket"
# Add as a service # Add as a service
yunohost service add "uwsgi-app@$app.service" --log "/var/log/uwsgi/app/$app" yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log"
} }
# Remove the dedicated uwsgi ini file # Remove the dedicated uwsgi ini file
# #
# usage: ynh_remove_systemd_config # usage: ynh_remove_uwsgi_service
ynh_remove_uwsgi_service () { ynh_remove_uwsgi_service () {
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
if [ -e "$finaluwsgiini" ]; then if [ -e "$finaluwsgiini" ]; then
systemctl stop "uwsgi-app@$app.service" systemctl stop "uwsgi-app@$app.socket"
systemctl disable "uwsgi-app@$app.service" systemctl disable "uwsgi-app@$app.socket"
yunohost service remove "uwsgi-app@$app.service" yunohost service remove "uwsgi-app@$app"
ynh_secure_remove "$finaluwsgiini" ynh_secure_remove "$finaluwsgiini"
ynh_secure_remove "/var/log/uwsgi/app/$app" ynh_secure_remove "/var/log/uwsgi/$app"
fi fi
} }

@ -113,12 +113,6 @@ ynh_system_user_create "$app" "$final_path"
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#=================================================
# SETUP UWSGI
#=================================================
ynh_add_uwsgi_service
#================================================= #=================================================
# create config file syncserver.ini # create config file syncserver.ini
#================================================= #=================================================
@ -176,6 +170,12 @@ virtualenv "$final_path/local"
cp -r ../sources/page $final_path/syncserver/ cp -r ../sources/page $final_path/syncserver/
(cd "$final_path/syncserver" && patch -p1 < $YNH_CWD/../sources/homepage.patch) || echo "Unable to apply patches" (cd "$final_path/syncserver" && patch -p1 < $YNH_CWD/../sources/homepage.patch) || echo "Unable to apply patches"
#=================================================
# SETUP UWSGI
#=================================================
ynh_add_uwsgi_service
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
@ -189,7 +189,7 @@ chmod u=rwX,g=rX,o= -R $final_path
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_use_logrotate ynh_use_logrotate /var/log/uwsgi/$app
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT

@ -197,7 +197,7 @@ chmod u=rwX,g=rX,o= -R $final_path
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_use_logrotate ynh_use_logrotate /var/log/uwsgi/$app --non-append
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT

Loading…
Cancel
Save