1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/scovie_ynh.git synced 2024-09-03 20:16:29 +02:00

Continue manifestv2

This commit is contained in:
Salamandar 2024-01-18 14:19:07 +01:00
parent 60a76f7a03
commit da4ec8d85d
15 changed files with 100 additions and 566 deletions

View file

@ -1,6 +1,8 @@
#!/usr/bin/env python3
""" """
Configuration for Gunicorn Configuration for Gunicorn
""" """
import multiprocessing import multiprocessing
@ -13,8 +15,8 @@ workers = multiprocessing.cpu_count() * 2 + 1
loglevel = 'info' loglevel = 'info'
# https://docs.gunicorn.org/en/latest/settings.html#logging # https://docs.gunicorn.org/en/latest/settings.html#logging
accesslog = '__LOG_FILE__' accesslog = '/var/log/__APP__/__APP__.log'
errorlog = '__LOG_FILE__' errorlog = '/var/log/__APP__/__APP__.log'
# https://docs.gunicorn.org/en/latest/settings.html#pidfile # https://docs.gunicorn.org/en/latest/settings.html#pidfile
pidfile = '__INSTALL_DIR__/gunicorn.pid' pidfile = '__INSTALL_DIR__/gunicorn.pid'

View file

@ -1,4 +1,4 @@
#!__INSTALL_DIR__/venv/bin/python #!/usr/bin/env python3
import os import os
import sys import sys

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
################################################################################ ################################################################################
################################################################################ ################################################################################
@ -9,7 +11,7 @@
################################################################################ ################################################################################
################################################################################ ################################################################################
from pathlib import Path as __Path from pathlib import Path
from django.contrib.admin.sites import AdminSite from django.contrib.admin.sites import AdminSite
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -24,13 +26,13 @@ from scovie.settings.prod import * # noqa:F401,F403 isort:skip
from django_yunohost_integration.base_settings import LOGGING # noqa:F401 isort:skip from django_yunohost_integration.base_settings import LOGGING # noqa:F401 isort:skip
INSTALL_DIR = __Path('__INSTALL_DIR__') # /opt/yunohost/$app INSTALL_DIR = Path('__INSTALL_DIR__')
assert INSTALL_DIR.is_dir(), f'Directory not exists: {INSTALL_DIR}' assert INSTALL_DIR.is_dir(), f'Directory not exists: {INSTALL_DIR}'
PUBLIC_PATH = __Path('__INSTALL_DIR__') # /var/www/$app PUBLIC_PATH = Path('__INSTALL_DIR__/public')
assert PUBLIC_PATH.is_dir(), f'Directory not exists: {PUBLIC_PATH}' assert PUBLIC_PATH.is_dir(), f'Directory not exists: {PUBLIC_PATH}'
LOG_FILE = __Path('__LOG_FILE__') # /var/log/$app/scovie_ynh.log LOG_FILE = Path('/var/log/__APP__/__APP__.log')
assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}' assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}'
PATH = '__PATH__' # $YNH_APP_ARG_PATH PATH = '__PATH__' # $YNH_APP_ARG_PATH

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
def setup_project_user(user): def setup_project_user(user):
""" """
All users used the Django admin, so we need to set the "staff" user flag. All users used the Django admin, so we need to set the "staff" user flag.

View file

@ -1,8 +1,8 @@
#!/usr/bin/env python3
""" """
urls.py urls.py
""" """
from django.conf import settings from django.conf import settings
from django.urls import include, path from django.urls import include, path
from django.views.generic import RedirectView from django.views.generic import RedirectView

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python3
""" """
WSGI config WSGI config
""" """
import os import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.core.wsgi import get_wsgi_application # noqa from django.core.wsgi import get_wsgi_application # noqa

View file

@ -1 +1,7 @@
[Scovie](https://github.com/eldertek/scovie) is an open-source digital signage system for high schools, built using Python and Django. It provides an easy-to-use interface for administrators to upload and manage multimedia content, which is then displayed on screens throughout the school. [Scovie](https://github.com/eldertek/scovie) is an open-source digital signage system for high schools, built using Python and Django.
It provides an easy-to-use interface for administrators to upload and manage multimedia content, which is then displayed on screens throughout the school.
## Links
* Report a bug about this package: <https://github.com/eldertek/scovie/issues>
* PyPi package: <https://pypi.org/project/scovie/>

View file

@ -1,87 +0,0 @@
## Links
* Report a bug about this package: https://github.com/eldertek/scovie/issues
* YunoHost website: https://yunohost.org/
* PyPi package: https://pypi.org/project/scovie/
These projects used `scovie`:
* https://github.com/eldertek/scovie
---
# Developer info
The App project will be stored under `__FINALPATH__` (e.g.: `/opt/yunohost/$app`) that's Django's `settings.FINALPATH`
"static" / "media" files to serve via nginx are under `__PUBLIC_PATH__` (e.g.: `/var/www/$app`) that's `settings.PUBLIC_PATH`
## package installation / debugging
This app is not in YunoHost app catalog. Test install, e.g.:
```bash
~# git clone https://github.com/eldertek/scovie_ynh.git
~# yunohost app install scovie_ynh/ -f
```
To update:
```bash
~# cd scovie_ynh
~/scovie_ynh# git fetch && git reset --hard origin/testing
~/scovie_ynh# yunohost app upgrade scovie_ynh -u . -F
```
To remove call e.g.:
```bash
sudo yunohost app remove scovie_ynh
```
Backup / remove / restore cycle, e.g.:
```bash
yunohost backup create --apps scovie_ynh
yunohost backup list
archives:
- scovie_ynh-pre-upgrade1
- 20201223-163434
yunohost app remove scovie_ynh
yunohost backup restore 20201223-163434 --apps scovie_ynh
```
Debug the installation, e.g.:
```bash
root@yunohost:~# cat /etc/yunohost/apps/scovie_ynh/settings.yml
...
root@yunohost:~# ls -la /var/www/scovie_ynh/
total 18
drwxr-xr-x 4 root root 4 Dec 8 08:36 .
drwxr-xr-x 6 root root 6 Dec 8 08:36 ..
drwxr-xr-x 2 root root 2 Dec 8 08:36 media
drwxr-xr-x 7 root root 8 Dec 8 08:40 static
root@yunohost:~# ls -la /opt/yunohost/scovie_ynh/
total 58
drwxr-xr-x 5 scovie_ynh scovie_ynh 11 Dec 8 08:39 .
drwxr-xr-x 3 root root 3 Dec 8 08:36 ..
-rw-r--r-- 1 scovie_ynh scovie_ynh 460 Dec 8 08:39 gunicorn.conf.py
-rw-r--r-- 1 scovie_ynh scovie_ynh 0 Dec 8 08:39 local_settings.py
-rwxr-xr-x 1 scovie_ynh scovie_ynh 274 Dec 8 08:39 manage.py
-rw-r--r-- 1 scovie_ynh scovie_ynh 171 Dec 8 08:39 secret.txt
drwxr-xr-x 6 scovie_ynh scovie_ynh 6 Dec 8 08:37 venv
-rw-r--r-- 1 scovie_ynh scovie_ynh 115 Dec 8 08:39 wsgi.py
-rw-r--r-- 1 scovie_ynh scovie_ynh 4737 Dec 8 08:39 scovie_ynh_demo_settings.py
root@yunohost:~# cd /opt/yunohost/scovie_ynh/
root@yunohost:/opt/yunohost/scovie_ynh# source venv/bin/activate
(venv) root@yunohost:/opt/yunohost/scovie_ynh# ./manage.py check
scovie_ynh v0.8.2 (Django v2.2.17)
DJANGO_SETTINGS_MODULE='scovie_ynh_demo_settings'
PROJECT_PATH:/opt/yunohost/scovie_ynh/venv/lib/python3.7/site-packages
BASE_PATH:/opt/yunohost/scovie_ynh
System check identified no issues (0 silenced).
root@yunohost:~# tail -f /var/log/scovie_ynh/scovie_ynh.log
root@yunohost:~# cat /etc/systemd/system/systemd.service
...
root@yunohost:~# systemctl reload-or-restart scovie_ynh
root@yunohost:~# journalctl --unit=scovie_ynh --follow
```

View file

@ -21,7 +21,6 @@ admin_email="${admin}@${domain}"
default_from_email="${app}@${domain}" default_from_email="${app}@${domain}"
public_path=/var/www/$app
#REMOVEME? install_dir=/opt/yunohost/$app #REMOVEME? install_dir=/opt/yunohost/$app
log_path=/var/log/$app log_path=/var/log/$app
log_file="${log_path}/${app}.log" log_file="${log_path}/${app}.log"

View file

@ -9,21 +9,6 @@
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_print_info --message="Loading installation settings..."
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain)
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP
#================================================= #=================================================
@ -34,27 +19,18 @@ ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
ynh_backup --src_path="$install_dir" ynh_backup --src_path="$install_dir"
ynh_backup --src_path="$public_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= ynh_backup --src_path="/etc/systemd/system/$app.service"
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= ynh_backup --src_path="/var/log/$app/"
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
#================================================= #=================================================
# BACKUP THE PostgreSQL DATABASE # BACKUP THE PostgreSQL DATABASE

View file

@ -12,75 +12,6 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN
#REMOVEME? old_path=$YNH_APP_OLD_PATH
#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN
#REMOVEME? new_path=$YNH_APP_NEW_PATH
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
#REMOVEME? admin=$(ynh_app_setting_get --app="$app" --key=admin)
#REMOVEME? public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir)
#REMOVEME? log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
#REMOVEME? port=$(ynh_app_setting_get --app="$app" --key=port)
#REMOVEME? db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name="$app")
#REMOVEME? db_user=$db_name
#REMOVEME? redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
#-------------------------------------------------
# config_panel.toml settings:
#REMOVEME? debug_enabled=$(ynh_app_setting_get --app="$app" --key=debug_enabled)
#REMOVEME? log_level=$(ynh_app_setting_get --app="$app" --key=log_level)
#REMOVEME? admin_email=$(ynh_app_setting_get --app="$app" --key=admin_email)
#REMOVEME? default_from_email=$(ynh_app_setting_get --app="$app" --key=default_from_email)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=40
# Backup the current version of the app
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
#REMOVEME? change_domain=0
#REMOVEME? if [ "$old_domain" != "$new_domain" ]
then
#REMOVEME? change_domain=1
fi
#REMOVEME? change_path=0
#REMOVEME? if [ "$old_path" != "$new_path" ]
then
#REMOVEME? change_path=1
fi
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
@ -99,39 +30,12 @@ ynh_script_progression --message="Updating NGINX web server configuration..."
ynh_change_url_nginx_config ynh_change_url_nginx_config
#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
#REMOVEME? # Change the path in the nginx config file
if [ $change_path -eq 1 ]
then
#REMOVEME? # Make a backup of the original nginx config file if modified
#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
#REMOVEME? # Set global variables for nginx helper
#REMOVEME? domain="$old_domain"
#REMOVEME? path="$new_path"
#REMOVEME? # Create a dedicated nginx config
#REMOVEME? ynh_add_nginx_config "public_path" "port"
fi
#REMOVEME? # Change the domain for nginx
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path"
#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#================================================= #=================================================
# SPECIFIC MODIFICATIONS # SPECIFIC MODIFICATIONS
#================================================= #=================================================
# MODIFY SETTINGS # MODIFY SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Modify $app config file..." ynh_script_progression --message="Modify $app config file..."
#REMOVEME?
domain=$YNH_APP_NEW_DOMAIN
path=$YNH_APP_NEW_PATH
ynh_add_config --template="settings.py" --destination="$install_dir/settings.py" ynh_add_config --template="settings.py" --destination="$install_dir/settings.py"
@ -144,13 +48,6 @@ ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
ynh_systemd_action --service_name="$app" --action="start" ynh_systemd_action --service_name="$app" --action="start"
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -27,14 +27,16 @@ ynh_app_setting_set --app="$app" --key=default_from_email --value="$default_from
#================================================= #=================================================
ynh_script_progression --message="Installing project via pip..." --weight=45 ynh_script_progression --message="Installing project via pip..." --weight=45
mkdir -p "$install_dir/media" "$install_dir/static"
_install_scovie_venv _install_scovie_venv
mkdir -p "$install_dir/public/media" "$install_dir/public/static"
chmod o-rwx "$install_dir" chmod o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir" chown -R "$app:www-data" "$install_dir"
mkdir -p "$log_path" mkdir -p "$log_path"
touch "$log_file" touch "$log_file"
chmod o-rwx "$log_path" chmod o-rwx "$log_path"
chown -R "$app:$app" "$log_path" chown -R "$app:$app" "$log_path"

View file

@ -10,92 +10,22 @@ source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # REMOVE SYSTEM CONFIGURATIONS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain)
#REMOVEME? db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#================================================= #=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# Remove a service from the admin panel, added by `yunohost service add` # Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status "$app" >/dev/null 2>&1 if yunohost service status "$app" >/dev/null 2>&1; then
then yunohost service remove "$app"
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove "$app"
fi fi
#================================================= ynh_remove_logrotate
# STOP PYINVENTORY'S SERVICES
#=================================================
ynh_script_progression --message="Stopping and removing systemd service '$app'..." --weight=5
ynh_remove_systemd_config --service="$app" ynh_remove_systemd_config --service="$app"
#=================================================
# REMOVE THE PostgreSQL DATABASE
#=================================================
#REMOVEME? ynh_script_progression --message="Removing the PostgreSQL database..."
# Remove a database if it exists, along with the associated user
#REMOVEME? ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
##=================================================
## REMOVE REDIS DB
##=================================================
ynh_redis_remove_db
#=================================================
# REMOVE DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=10
# Remove metapackage and its dependencies
#REMOVEME? ynh_exec_warn_less ynh_remove_app_dependencies
#=================================================
# REMOVE APP MAIN DIR
#=================================================
#REMOVEME? ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely
ynh_secure_remove --file="$public_path"
#REMOVEME? ynh_secure_remove --file="$install_dir"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= ynh_redis_remove_db "$redis_db"
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..."
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..."
# Delete a system user
#REMOVEME? ynh_system_user_delete --username="$app"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -9,74 +9,22 @@
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..."
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir)
#REMOVEME? public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
#REMOVEME? db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app="$app" --key=path)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
#REMOVEME? ynh_script_progression --message="Validating restoration parameters..."
#REMOVEME? test ! -d $install_dir \
|| ynh_die --message="There is already a directory: $install_dir "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring $app main directory..." ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$install_dir" ynh_restore_file --origin_path="$install_dir"
ynh_restore_file --origin_path="$public_path"
chmod o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RESTORE THE POSTGRES DATABASE
#================================================= #=================================================
#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." ynh_script_progression --message="Restoring the Postgresql database..." --weight=1
# Create the dedicated user (if not existing) ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" --use_shell
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R "$app:www-data" "$public_path"
chown -R "$app:" "$install_dir"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=20
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
#================================================= #=================================================
# PYTHON VIRTUALENV # PYTHON VIRTUALENV
@ -97,77 +45,41 @@ chown -R "$app:" "$install_dir"
ynh_script_progression --message="Install project via pip..." --weight=45 ynh_script_progression --message="Install project via pip..." --weight=45
#run source in a 'sub shell' #run source in a 'sub shell'
( (
set +o nounset set +o nounset
source "${install_dir}/venv/bin/activate" source "${install_dir}/venv/bin/activate"
set -o nounset set -o nounset
ynh_exec_as $app $install_dir/venv/bin/python3 -m ensurepip ynh_exec_as $app $install_dir/venv/bin/python3 -m ensurepip
ynh_exec_as $app $install_dir/venv/bin/pip3 install --upgrade wheel pip setuptools ynh_exec_as $app $install_dir/venv/bin/pip3 install --upgrade wheel pip setuptools
ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-deps -r "$install_dir/requirements.txt" ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-deps -r "$install_dir/requirements.txt"
) )
#================================================= #=================================================
# RESTORE THE PostgreSQL DATABASE # RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
#REMOVEME? ynh_psql_test_if_first_run ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#REMOVEME? ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd"
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="Digital signage system for high schools" --log="$log_file"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Digital signage system for high schools" --log="${log_file}"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
mkdir -p "$log_path"
touch "${log_file}"
chown -R "$app:" "$log_path"
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= ynh_restore_file --origin_path="/var/log/$app/"
# GENERIC FINALIZATION chmod o-rwx "/var/log/$app"
#================================================= chown -R "$app:" "/var/log/$app"
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R "$app:" "$log_path"
chown -R "$app:www-data" "$public_path"
chown -R "$app:" "$install_dir"
chmod o-rwx "$log_path"
chmod o-rwx "$public_path"
chmod o-rwx "$install_dir"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# START PYINVENTORY # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
#================================================= ynh_systemd_action --service_name=nginx --action=reload
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name="nginx" --action="reload"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -8,66 +8,31 @@ source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # STANDARD UPGRADE STEPS
#================================================= #=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." # ENSURE DOWNWARD COMPATIBILITY
#REMOVEME? admin=$(ynh_app_setting_get --app="$app" --key=admin)
#REMOVEME? public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir)
#REMOVEME? log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app="$app" --key=path)
#REMOVEME? port=$(ynh_app_setting_get --app="$app" --key=port)
#REMOVEME? db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name="$app")
#REMOVEME? db_user=$db_name
#REMOVEME? redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
#-------------------------------------------------
# config_panel.toml settings:
#REMOVEME? debug_enabled=$(ynh_app_setting_get --app="$app" --key=debug_enabled)
if [ -z "$debug_enabled" ]; then
debug_enabled="0"
ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
fi
#REMOVEME? log_level=$(ynh_app_setting_get --app="$app" --key=log_level)
if [ -z "$log_level" ]; then
log_level="WARNING"
ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
fi
#REMOVEME? admin_email=$(ynh_app_setting_get --app="$app" --key=admin_email)
if [ -z "$admin_email" ]; then
admin_email="${admin}@${domain}"
#REMOVEME? ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
fi
#REMOVEME? default_from_email=$(ynh_app_setting_get --app="$app" --key=default_from_email)
if [ -z "$default_from_email" ]; then
default_from_email="${app}@${domain}"
ynh_app_setting_set --app="$app" --key=default_from_email --value="$default_from_email"
fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
#=================================================
ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=40
# Backup the current version of the app if [ -z "${debug_enabled:-}" ]; then
#REMOVEME? ynh_backup_before_upgrade debug_enabled="0"
#REMOVEME? ynh_clean_setup () { ynh_app_setting_set --app="$app" --key=debug_enabled --value="$debug_enabled"
# restore it if the upgrade fails fi
#REMOVEME? ynh_restore_upgradebackup
} if [ -z "${log_level:-}" ]; then
# Exit if an error occurs during the execution of the script log_level="WARNING"
#REMOVEME? ynh_abort_if_errors ynh_app_setting_set --app="$app" --key=log_level --value="$log_level"
fi
if [ -z "${admin_email:-}" ]; then
admin_email="${admin}@${domain}"
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
fi
if [ -z "${default_from_email:-}" ]; then
default_from_email="${app}@${domain}"
ynh_app_setting_set --app="$app" --key=default_from_email --value="$default_from_email"
fi
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
@ -76,69 +41,20 @@ ynh_script_progression --message="Backing up $app before upgrading (may take a w
#================================================= #=================================================
ynh_script_progression --message="Stopping systemd service '$app'..." --weight=5 ynh_script_progression --message="Stopping systemd service '$app'..." --weight=5
ynh_systemd_action --service_name="$app" --action="stop" ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config
# https://yunohost.org/en/contribute/packaging_apps/helpers
# https://github.com/YunoHost/yunohost/blob/dev/helpers/nginx
ynh_add_nginx_config "public_path" "port"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# Update dependencies
#=================================================
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=20
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# CREATE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a system user
#REMOVEME? ynh_system_user_create --username="$app" --home_dir="$install_dir" --use_shell
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5
ynh_add_systemd_config --service="$app" --template="systemd.service"
#=================================================
# PYTHON VIRTUALENV
#=================================================
ynh_script_progression --message="Recreate Python virtualenv..." --weight=5
# Always recreate everything fresh with current python version
ynh_secure_remove "${install_dir}/venv"
# Skip pip because of: https://github.com/YunoHost/issues/issues/1960
python3 -m venv --without-pip "${install_dir}/venv"
cp ../conf/requirements.txt "$install_dir/requirements.txt"
chown -R "$app:" "$install_dir"
#================================================= #=================================================
# PIP INSTALLATION # PIP INSTALLATION
#================================================= #=================================================
ynh_script_progression --message="Install project via pip..." --weight=45 ynh_script_progression --message="Installing project via pip..." --weight=45
#run source in a 'sub shell'
( # Always recreate everything fresh with current python version
set +o nounset ynh_secure_remove "$install_dir/venv"
source "${install_dir}/venv/bin/activate"
set -o nounset _install_scovie_venv
ynh_exec_as $app $install_dir/venv/bin/python3 -m ensurepip
ynh_exec_as $app $install_dir/venv/bin/pip3 install --upgrade wheel pip setuptools chmod o-rwx "$install_dir"
ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-deps -r "$install_dir/requirements.txt" chown -R "$app:www-data" "$install_dir"
)
#================================================= #=================================================
# copy config files # copy config files
@ -175,36 +91,19 @@ cd "$install_dir" || exit
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later. # This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
./manage.py check --deploy || true ./manage.py check --deploy || true
#================================================= #=================================================
# SETUP LOGROTATE # REAPPLY SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_add_nginx_config
ynh_add_systemd_config --service="$app" --template="systemd.service"
yunohost service add "$app" --description="Digital signage system for high schools" --log="/var/log/$app/$app.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Digital signage system for high schools" --log="${log_file}"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R "$app:" "$log_path"
chown -R "$app:www-data" "$public_path"
chown -R "$app:" "$install_dir"
chmod o-rwx "$log_path" chmod o-rwx "$log_path"
chmod o-rwx "$public_path" chown -R "$app:" "$log_path"
chmod o-rwx "$install_dir"
#================================================= #=================================================
# Start the app server via systemd # Start the app server via systemd
@ -213,13 +112,6 @@ ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
ynh_systemd_action --service_name="$app" --action="start" ynh_systemd_action --service_name="$app" --action="start"
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================