diff --git a/README.md b/README.md index cc53801..a218918 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ @@ -19,7 +19,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in This is the webservice powering the https://gpodder.net website. It can be used to sync podcast subscriptions with [supported clients](https://gpoddernet.readthedocs.io/en/latest/user/clients.html). -**Shipped version:** 2.11.20221222~ynh1 +**Shipped version:** 2.11.20221222~ynh2 **Demo:** https://gpodder.net @@ -27,16 +27,6 @@ This is the webservice powering the https://gpodder.net website. It can be used ![Screenshot of mygpo (gPodder.net)](./doc/screenshots/screenshot1.png) -## Disclaimers / important information - -## Limitations - -* The feed-parsing service is not included, https://feeds.gpodder.net is used - -## Configuration - -Edit files under `/opt/yunohost/APPDIR/envs/prod` to set environment variables. There is an admin interface at `yourdomain.tld/admin` that the admin user can log in to. - ## Documentation and resources * Official app website: @@ -57,4 +47,4 @@ or sudo yunohost app upgrade mygpo -u https://github.com/YunoHost-Apps/mygpo_ynh/tree/testing --debug ``` -**More info regarding app packaging:** +**More info regarding app packaging:** \ No newline at end of file diff --git a/README_fr.md b/README_fr.md index 00278cb..9e0fffb 100644 --- a/README_fr.md +++ b/README_fr.md @@ -1,5 +1,5 @@ @@ -19,7 +19,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po This is the webservice powering the https://gpodder.net website. It can be used to sync podcast subscriptions with [supported clients](https://gpoddernet.readthedocs.io/en/latest/user/clients.html). -**Version incluse :** 2.11.20221222~ynh1 +**Version incluse :** 2.11.20221222~ynh2 **Démo :** https://gpodder.net @@ -27,16 +27,6 @@ This is the webservice powering the https://gpodder.net website. It can be used ![Capture d’écran de mygpo (gPodder.net)](./doc/screenshots/screenshot1.png) -## Avertissements / informations importantes - -## Limitations - -* The feed-parsing service is not included, https://feeds.gpodder.net is used - -## Configuration - -Edit files under `/opt/yunohost/APPDIR/envs/prod` to set environment variables. There is an admin interface at `yourdomain.tld/admin` that the admin user can log in to. - ## Documentations et ressources * Site officiel de l’app : diff --git a/check_process b/check_process deleted file mode 100644 index d898e6a..0000000 --- a/check_process +++ /dev/null @@ -1,30 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - is_public=1 - admin="john" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - # 2.11.1~ynh3 - upgrade=1 from_commit=a50d46ae3a01d8a5b08ca9f9e62bfc9269fdedfa - # 2.11.20210519~ynh1 - upgrade=1 from_commit=59b41b65dc33c3da471175002f37576ff460dc46 - # 2.11.20211020~ynh1 - upgrade=1 from_commit=8284155ea371f4b8a9f0c333d486c5a2342acfae - backup_restore=1 - multi_instance=0 - port_already_use=0 - change_url=1 -;;; Options -Email= -Notification=none -;;; Upgrade options - ; commit=CommitHash - name=Tweak starting of systemd services (April 1) - manifest_arg=domain=DOMAIN&admin=USER&is_public=1& diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index bcd61a5..0000000 --- a/conf/app.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://github.com/gpodder/mygpo/archive/80c41dc0c9a58dc0e85f6ef56662cdfd0d6e3b16.tar.gz -SOURCE_SUM=cce51ef812e5a692ea38b82cb559a4982dcf76ad34d6adf73aff2c5299cb5573 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/nginx.conf b/conf/nginx.conf index f284493..168b62c 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,4 @@ -root __FINALPATH__/static; +root __INSTALL_DIR__/static; location /media { root /home/yunohost.app/__NAME__; @@ -7,7 +7,7 @@ location /media { } location /static/ { - alias __FINALPATH__/static/; + alias __INSTALL_DIR__/static/; } location /logo { @@ -45,12 +45,12 @@ location @proxy_to_app { proxy_set_header Connection "upgrade"; } -location /media/admin { - alias __FINALPATH__/venv/lib/python3.7/site-packages/django/contrib/admin/static/admin; +location /media/admin/ { + alias __INSTALL_DIR__/venv/lib/python3.7/site-packages/django/contrib/admin/static/admin/; } -location /static/admin { - alias __FINALPATH__/venv/lib/python3.7/site-packages/django/contrib/admin/static/admin; +location /static/admin/ { + alias __INSTALL_DIR__/venv/lib/python3.7/site-packages/django/contrib/admin/static/admin/; } location ~ /(favicon.ico|favicon.png|robots.txt|clientconfig.json) { diff --git a/sources/extra_files/app/requirements-ynh.txt b/conf/requirements-ynh.txt similarity index 100% rename from sources/extra_files/app/requirements-ynh.txt rename to conf/requirements-ynh.txt diff --git a/conf/systemd-beat.service b/conf/systemd-beat.service index 56e7757..5cbbfb7 100644 --- a/conf/systemd-beat.service +++ b/conf/systemd-beat.service @@ -5,9 +5,9 @@ After=network.target postgresql.service redis.service __APP__.scoket [Service] User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__ +WorkingDirectory=__INSTALL_DIR__/sources/ -ExecStart=__FINALPATH__/venv/bin/envdir __FINALPATH__/envs/prod __FINALPATH__/venv/bin/celery -A __APP__ beat --pidfile /tmp/celerybeat.pid -S django +ExecStart=__INSTALL_DIR__/venv/bin/envdir __INSTALL_DIR__/envs/prod __INSTALL_DIR__/venv/bin/celery -A __APP__ beat --pidfile /tmp/celerybeat.pid -S django ExecReload=/bin/kill -s HUP $MAINPID Restart=on-failure KillMode=mixed @@ -15,4 +15,4 @@ TimeoutStopSec=5 PrivateTmp=true [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/conf/systemd-celery.service b/conf/systemd-celery.service index 6235004..3b3074d 100644 --- a/conf/systemd-celery.service +++ b/conf/systemd-celery.service @@ -5,9 +5,9 @@ After=network.target postgresql.service redis.service __APP__.socket [Service] User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__ +WorkingDirectory=__INSTALL_DIR__/sources/ -ExecStart=__FINALPATH__/venv/bin/envdir __FINALPATH__/envs/prod __FINALPATH__/venv/bin/celery -A __APP__ worker -l info -Ofair +ExecStart=__INSTALL_DIR__/venv/bin/envdir __INSTALL_DIR__/envs/prod __INSTALL_DIR__/venv/bin/celery -A __APP__ worker -l info -Ofair ExecReload=/bin/kill -s HUP $MAINPID Restart=on-failure KillMode=mixed @@ -15,4 +15,4 @@ TimeoutStopSec=5 PrivateTmp=true [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/conf/systemd.service b/conf/systemd.service index 1ac6082..7eb4da5 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,9 +7,9 @@ Requires=__APP__.socket Type=notify User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__/ +WorkingDirectory=__INSTALL_DIR__/sources/ -ExecStart=__FINALPATH__/venv/bin/envdir __FINALPATH__/envs/prod __FINALPATH__/venv/bin/gunicorn -c __FINALPATH__/conf/gunicorn.conf.py mygpo.wsgi:application --bind unix:/run/__APP__.sock +ExecStart=__INSTALL_DIR__/venv/bin/envdir __INSTALL_DIR__/envs/prod __INSTALL_DIR__/venv/bin/gunicorn -c __INSTALL_DIR__/sources/conf/gunicorn.conf.py mygpo.wsgi:application --bind unix:/run/__APP__.sock ExecReload=/bin/kill -s HUP $MAINPID Restart=on-failure KillMode=mixed diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index d8a9a58..0000000 --- a/doc/DISCLAIMER.md +++ /dev/null @@ -1,7 +0,0 @@ -## Limitations - -* The feed-parsing service is not included, https://feeds.gpodder.net is used - -## Configuration - -Edit files under `/opt/yunohost/APPDIR/envs/prod` to set environment variables. There is an admin interface at `yourdomain.tld/admin` that the admin user can log in to. diff --git a/doc/POST_INSTALL.md b/doc/POST_INSTALL.md new file mode 100644 index 0000000..adcca03 --- /dev/null +++ b/doc/POST_INSTALL.md @@ -0,0 +1,3 @@ +## Configuration + +Edit files under `__INSTALL_DIR__/envs/prod` to set environment variables. There is an admin interface at `yourdomain.tld/admin` that the admin user can log in to. diff --git a/doc/PRE_INSTALL.md b/doc/PRE_INSTALL.md new file mode 100644 index 0000000..8face07 --- /dev/null +++ b/doc/PRE_INSTALL.md @@ -0,0 +1,3 @@ +## Limitations + +* The feed-parsing service is not included, https://feeds.gpodder.net is used diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 3c3a136..0000000 --- a/manifest.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "mygpo (gPodder.net)", - "id": "mygpo", - "packaging_format": 1, - "description": { - "en": "Manage podcast subscriptions, and sync them between apps and devices", - "fr": "Gérez vos sousciptions balado, et sychronisez-lez entre vos applis et appareils" - }, - "version": "2.11.20221222~ynh1", - "url": "https://github.com/gpodder/mygpo", - "upstream": { - "license": "AGPL-3.0-only", - "website": "https://gpodder.net", - "demo": "https://gpodder.net", - "admindoc": "https://gpoddernet.readthedocs.io/", - "code": "https://github.com/gpodder/mygpo" - }, - "license": "AGPL-3.0-only", - "maintainer": { - "name": "Jules Bertholet", - "email": "jules.bertholet@gmail.com" - }, - "requirements": { - "yunohost": ">= 11.0.9" - }, - "multi_instance": false, - "services": [ - "nginx", - "postgresql", - "redis-server" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "is_public", - "type": "boolean", - "help": { - "en": "If set to public, anybody will be able to create an account and access some statistics about usage of the app. If set to private, some parts of the API will be blocked off", - "fr": "Si public, n'importe-qui pourra créer un compte et accéder a certaines statistiques d'utilization. Si privé, certaines parties de l'API seront inaccessibles" - }, - "default": true - }, - { - "name": "admin", - "type": "user" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..9a2e661 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,91 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "mygpo" +name = "mygpo (gPodder.net)" +description.en = "Manage podcast subscriptions, and sync them between apps and devices" +description.fr = "Gérez vos sousciptions balado, et sychronisez-lez entre vos applis et appareils" + +version = "2.11.20221222~ynh2" + +maintainers = ["Jules Bertholet"] + +[upstream] +license = "AGPL-3.0-only" +website = "https://gpodder.net" +demo = "https://gpodder.net" +admindoc = "https://gpoddernet.readthedocs.io/" +code = "https://github.com/gpodder/mygpo" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = false +ldap = true +sso = false +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.domain] + type = "domain" + + [install.init_main_permission] + help.en = "If set to public, anybody will be able to create an account and access some statistics about usage of the app. If set to private, some parts of the API will be blocked off" + help.fr = "Si public, n'importe-qui pourra créer un compte et accéder a certaines statistiques d'utilization. Si privé, certaines parties de l'API seront inaccessibles" + type = "group" + default = "visitors" + + [install.admin] + type = "user" + +[resources] + [resources.sources.main] + url = "https://github.com/gpodder/mygpo/archive/80c41dc0c9a58dc0e85f6ef56662cdfd0d6e3b16.tar.gz" + sha256 = "cce51ef812e5a692ea38b82cb559a4982dcf76ad34d6adf73aff2c5299cb5573" + + autoupdate.strategy = "latest_github_commit" + + [resources.system_user] + + [resources.install_dir] + + [resources.data_dir] + + [resources.permissions] + main.url = "/" + api.url = "/api" + api.additional_urls = ["/clientconfig.json", "/subscriptions", "/suggestions"] + api.allowed = "visitors" + api.protected = true + + api_noauth.url = "/toplist" + api_noauth.additional_urls = ["/api/2/data", "/api/2/tag", "/api/2/tags", "/search.opml", "/search.json", "/search.jsonp", "/search.txt", "/search.xml", "/toplist.opml"] + api_noauth.allowed = "visitors" + + api_lists.url = "/api/2/lists" + api_lists.allowed = "visitors" + + [resources.apt] + packages = [ + "acl", + "libffi-dev", + "libjpeg-dev", + "libwebp-dev", + "python3", + "python3-dev", + "python3-pip", + "python3-venv", + "libpq-dev", + "redis-server", + "libldap2-dev", + "libsasl2-dev", + + "postgresql", + "postgresql-contrib", + ] + + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index ffd8858..3b9cc22 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,77 +4,46 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies="acl libffi-dev libjpeg-dev libwebp-dev python3 python3-dev python3-pip python3-venv postgresql postgresql-contrib libpq-dev redis-server libldap2-dev libsasl2-dev" +env_path="$install_dir/envs/prod" #================================================= # PERSONAL HELPERS #================================================= function set_permissions { - mkdir -p $datadir + chmod 750 "$data_dir" + chown -R "$app:$app" "$data_dir" + setfacl -n -R -m u:www-data:rx -m d:u:www-data:rx "$data_dir" - env_path=$final_path/envs/prod - mkdir -p $env_path - - chown -R $app:$app $datadir - chmod o-rwx $datadir - setfacl -n -R -m u:www-data:rx -m d:u:www-data:rx $datadir - - chown -R root:$app $final_path - chmod -R g=u,g-w,o-rwx $final_path - setfacl -n -R -m user:www-data:rx -m default:user:www-data:rx $final_path - setfacl -n -R -m user:www-data:- -m default:user:www-data:- $final_path/envs + chmod 750 "$install_dir" + chown -R "$app:$app" "$install_dir" + setfacl -n -R -m user:www-data:rx -m default:user:www-data:rx "$install_dir" + setfacl -n -R -m user:www-data:- -m default:user:www-data:- "$install_dir/envs" } function set_up_virtualenv { - env_path=$final_path/envs/prod - mkdir -p $env_path + mkdir -p "$env_path" + ynh_add_config --template="requirements-ynh.txt" --destination="$install_dir/requirements-ynh.txt" - pushd $final_path || ynh_die - chown -R $app:$app $final_path - ynh_exec_warn_less ynh_exec_as $app python3 -m venv $final_path/venv - ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/pip --cache-dir $final_path/.cache/pip install -U wheel pip --cache-dir $final_path/.cache/pip setuptools - ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/pip --cache-dir $final_path/.cache/pip install -U --requirement $final_path/requirements.txt - ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/pip --cache-dir $final_path/.cache/pip install -U --requirement $final_path/requirements-setup.txt - ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/pip --cache-dir $final_path/.cache/pip install -U --requirement $final_path/requirements-ynh.txt - set_permissions - popd || ynh_dies + ynh_exec_warn_less ynh_exec_as "$app" python3 -m venv "$install_dir/venv" + ynh_exec_warn_less ynh_exec_as "$app" "$install_dir/venv/bin/pip" --cache-dir "$install_dir/.cache/pip" install -U wheel pip --cache-dir "$install_dir/.cache/pip" setuptools + ynh_exec_warn_less ynh_exec_as "$app" "$install_dir/venv/bin/pip" --cache-dir "$install_dir/.cache/pip" install -U --requirement "$install_dir/sources/requirements.txt" + ynh_exec_warn_less ynh_exec_as "$app" "$install_dir/venv/bin/pip" --cache-dir "$install_dir/.cache/pip" install -U --requirement "$install_dir/sources/requirements-setup.txt" + ynh_exec_warn_less ynh_exec_as "$app" "$install_dir/venv/bin/pip" --cache-dir "$install_dir/.cache/pip" install -U --requirement "$install_dir/requirements-ynh.txt" } function initialize_db { - pushd $final_path || ynh_die - chown -R $app:$app $final_path - perform_db_migrations - ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/envdir $env_path $final_path/venv/bin/python $final_path/manage.py createsuperuser --username "$admin" --email "$admin_email" --noinput -v 0 - set_permissions - popd || ynh_die + perform_db_migrations + ynh_exec_warn_less ynh_exec_as "$app" "$install_dir/venv/bin/envdir" "$env_path" "$install_dir/venv/bin/python" "$install_dir/sources/manage.py" createsuperuser --username "$admin" --email "$admin_email" --noinput -v 0 } function upgrade_db { - pushd $final_path || ynh_die - chown -R $app:$app $final_path - perform_db_migrations - set_permissions - popd || ynh_die + perform_db_migrations } function perform_db_migrations { - echo "y" | ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/envdir $env_path $final_path/venv/bin/python $final_path/manage.py makemigrations --merge - ynh_exec_warn_less ynh_exec_as $app $final_path/venv/bin/envdir $env_path $final_path/venv/bin/python $final_path/manage.py migrate -} - -function get_app_settings { - domain=$(ynh_app_setting_get --app=$app --key=domain) - path_url=$(ynh_app_setting_get --app=$app --key=path) - final_path=$(ynh_app_setting_get --app=$app --key=final_path) - datadir=$(ynh_app_setting_get --app=$app --key=datadir) - admin=$(ynh_app_setting_get --app=$app --key=admin) - secret_key=$(ynh_app_setting_get --app=$app --key=secret_key) - admin_email=$(ynh_user_get_info --username=$admin --key="mail") - db_name=$(ynh_app_setting_get --app=$app --key=db_name) - db_user="$db_name" - db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) + yes | ynh_exec_warn_less ynh_exec_as "$app" "$install_dir/venv/bin/envdir" "$env_path" "$install_dir/venv/bin/python" "$install_dir/sources/manage.py" makemigrations --merge + ynh_exec_warn_less ynh_exec_as "$app" "$install_dir/venv/bin/envdir" "$env_path" "$install_dir/venv/bin/python" "$install_dir/sources/manage.py" migrate } #================================================= diff --git a/scripts/backup b/scripts/backup index bfc4d1b..37e8cfa 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,25 +8,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -get_app_settings - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -38,13 +17,13 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE DATA DIR #================================================= -ynh_backup --src_path="$datadir" --is_big +ynh_backup --src_path="$data_dir" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION @@ -52,18 +31,11 @@ ynh_backup --src_path="$datadir" --is_big ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP SYSTEMD -#================================================= - ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app-celery.service" ynh_backup --src_path="/etc/systemd/system/$app-beat.service" ynh_backup --src_path="/etc/systemd/system/$app.socket" - #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= diff --git a/scripts/change_url b/scripts/change_url index 5a44357..c2bd411 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,115 +7,44 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path="/" - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -get_app_settings - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_clean_check_starting - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICES #================================================= -ynh_script_progression --message="Stopping systemd services..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd services..." --weight=1 -ynh_systemd_action --service_name=$app-celery --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-beat --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app.socket --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app.socket" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # MODIFY URL IN NGINX CONF #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi +ynh_change_url_nginx_config #================================================= # SPECIFIC MODIFICATIONS #================================================= -echo $new_domain > $final_path/envs/prod/DEFAULT_BASE_URL -echo "$app@$new_domain" > $final_path/envs/prod/DEFAULT_FROM_EMAIL -echo "$app@$new_domain" > $final_path/envs/prod/SERVER_EMAIL +ynh_script_progression --message="Updating $app's configuration files..." --weight=1 + +mkdir -p "$env_path" +echo "$new_domain" > "$env_path/DEFAULT_BASE_URL" +echo "$app@$new_domain" > "$env_path/DEFAULT_FROM_EMAIL" +echo "$app@$new_domain" > "$env_path/SERVER_EMAIL" set_permissions -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICES #================================================= ynh_script_progression --message="Starting systemd services..." --weight=1 -ynh_systemd_action --service_name=$app.socket --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-celery --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-beat --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app.socket" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 6dadb55..f862915 100755 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,127 +8,45 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INITIALIZE AND STORE SETTINGS #================================================= -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -domain=$YNH_APP_ARG_DOMAIN -path_url="/" -is_public=$YNH_APP_ARG_IS_PUBLIC -admin=$YNH_APP_ARG_ADMIN - -app=$YNH_APP_INSTANCE_NAME - -admin_email=$(ynh_user_get_info --username=$admin --key="mail") +admin_email=$(ynh_user_get_info --username="$admin" --key="mail") secret_key=$(ynh_string_random --length=64) staff_token=$(ynh_string_random --length=64) -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 - -final_path=/opt/yunohost/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 - -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=path --value=$path_url -ynh_app_setting_set --app=$app --key=admin --value=$admin -ynh_app_setting_set --app=$app --key=random_key --value=$secret_key - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=3 - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path - -#================================================= -# CREATE A POSTGRESQL DATABASE -#================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." - -db_name=$(ynh_sanitize_dbid --db_name=$app) -db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name -ynh_psql_execute_as_root --sql="ALTER ROLE $db_user SET statement_timeout = 5000;" --database=$db_name +ynh_app_setting_set --app="$app" --key="secret_key" --value="$secret_key" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 -ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$final_path" +ynh_setup_source --dest_dir="$install_dir/sources" #================================================= -# NGINX CONFIGURATION +# APP INITIAL CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=1 +ynh_script_progression --message="Adding $app's configuration files..." --weight=1 -# Create a dedicated NGINX config -ynh_add_nginx_config +mkdir -p "$env_path" -#================================================= -# SPECIFIC SETUP -#================================================= -# CREATE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Creating a data directory..." - -datadir=/home/yunohost.app/$app -ynh_app_setting_set --app=$app --key=datadir --value=$datadir +echo "$admin <$admin_email>" > "$env_path/ADMINS" +echo "None" > "$env_path/BROKER_POOL_LIMIT" +echo "redis://localhost:6379" > "$env_path/BROKER_URL" +echo "postgres://$db_user:$db_pwd@localhost:5432/$db_name" > "$env_path/DATABASE_URL" +echo "False" > "$env_path/DEBUG" +echo "$domain" > "$env_path/DEFAULT_BASE_URL" +echo "$app@$domain" > "$env_path/DEFAULT_FROM_EMAIL" +echo "django.core.mail.backends.console.EmailBackend" > "$env_path/EMAIL_BACKEND" +echo "$data_dir" > "$env_path/MEDIA_ROOT" +echo "$secret_key" > "$env_path/SECRET_KEY" +echo "$app@$domain" > "$env_path/SERVER_EMAIL" +echo "$staff_token" > "$env_path/STAFF_TOKEN" set_permissions -#================================================= -# ENVDIR CONFIGURATION -#================================================= -ynh_script_progression --message="Building configuration..." --weight=1 - -echo "$admin <$admin_email>" > $env_path/ADMINS -echo "None" > $env_path/BROKER_POOL_LIMIT -echo "redis://localhost:6379" > $env_path/BROKER_URL -echo "postgres://$db_user:$db_pwd@localhost:5432/$db_name" > $env_path/DATABASE_URL -echo False > $env_path/DEBUG -echo $domain > $env_path/DEFAULT_BASE_URL -echo "$app@$domain" > $env_path/DEFAULT_FROM_EMAIL -echo "django.core.mail.backends.console.EmailBackend" > $env_path/EMAIL_BACKEND -echo "$datadir" > $env_path/MEDIA_ROOT -echo $secret_key > $env_path/SECRET_KEY -echo "$app@$domain" > $env_path/SERVER_EMAIL -echo $staff_token > $env_path/STAFF_TOKEN - #================================================= # SET UP VIRTUALENV #================================================= @@ -143,70 +59,41 @@ set_up_virtualenv #================================================= ynh_script_progression --message="Initializing database..." +ynh_psql_execute_as_root --sql="ALTER ROLE $db_user SET statement_timeout = 5000;" --database="$db_name" + initialize_db +set_permissions + #================================================= -# SETUP SYSTEMD +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring systemd services..." --weight=1 +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config -ynh_add_systemd_config --service="$app-socket" --template systemd.socket +yunohost service add "$app" --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log" ynh_add_systemd_config --service="$app-celery" --template systemd-celery.service ynh_add_systemd_config --service="$app-beat" --template systemd-beat.service +# Some workaround bc ynh_add_system_config doesn't know sockets +ynh_add_systemd_config --service="$app-socket" --template systemd.socket systemctl disable "$app-socket.service" --quiet mv "/etc/systemd/system/$app-socket.service" "/etc/systemd/system/$app.socket" systemctl daemon-reload --quiet -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting systemd services..." --weight=1 +ynh_script_progression --message="Starting $app's systemd services..." --weight=1 # Start systemd services -ynh_systemd_action --service_name=$app.socket --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-celery --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-beat --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 - -# Everyone can access to the api part -# We don't want to display the tile in the sso so we put --show_tile="false" -# And we don't want that the YunoHost Admin can remove visitors group to this permission, so we put --protected="true" -ynh_permission_create --permission="api" --url="/api" -A "/clientconfig.json" "/subscriptions" "/suggestions" --allowed="visitors" --show_tile="false" --protected="true" -ynh_permission_create --permission="api-noauth" --url="/toplist" -A "/api/2/data" "/api/2/tag" "/api/2/tags" "/search.opml" "/search.json" "/search.jsonp" "/search.txt" "/search.xml" "/toplist.opml" --show_tile="false" -ynh_permission_create --permission="api-lists" --url="/api/2/lists" --show_tile="false" - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. - ynh_permission_update --permission="main" --add="visitors" - ynh_permission_update --permission="api-noauth" --add="visitors" - ynh_permission_update --permission="api-lists" --add="visitors" -fi - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app.socket" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index fe4f4f6..a194bca 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,87 +8,28 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -get_app_settings - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service integration..." --weight=1 - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - # Remove the dedicated systemd config -systemctl stop $app.socket --quiet -systemctl disable $app.socket --quiet -rm /etc/systemd/system/$app.socket +systemctl stop "$app.socket" --quiet +systemctl disable "$app.socket" --quiet +rm "/etc/systemd/system/$app.socket" systemctl daemon-reload --quiet ynh_remove_systemd_config -ynh_remove_systemd_config -s $app-celery -ynh_remove_systemd_config -s $app-beat - -#================================================= -# REMOVE THE POSTGRESQL DATABASE -#================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1 - -# Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE DATA DIR -#================================================= - -# Remove the data directory if --purge option is used -if [ "${YNH_APP_PURGE:-0}" -eq 1 ] -then - ynh_script_progression --message="Removing app data directory..." - ynh_secure_remove --file="$datadir" -fi - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +ynh_remove_systemd_config -s "$app-celery" +ynh_remove_systemd_config -s "$app-beat" # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= @@ -99,16 +38,6 @@ ynh_script_progression --message="Removing various files..." # Remove the log files ynh_secure_remove --file="/var/log/$app" -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 - -# Delete a system user -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index fb49491..45484f9 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,134 +8,69 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -get_app_settings - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path - #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= ynh_script_progression --message="Restoring the data directory..." -ynh_restore_file --origin_path="$datadir" --not_mandatory +ynh_restore_file --origin_path="$data_dir" --not_mandatory -mkdir -p $datadir - -chmod 750 "$datadir" -chmod -R o-rwx "$datadir" -chown -R $app:www-data "$datadir" +chmod -R o-rwx "$data_dir" +chown -R "$app:www-data" "$data_dir" #================================================= -# SPECIFIC RESTORATION +# RESTORE THE DATA DIRECTORY #================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=1 +ynh_script_progression --message="Restoring the data directory..." --weight=1 -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies +ynh_restore_file --origin_path="$data_dir" --not_mandatory -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." +chown -R "$app:www-data" "$data_dir" -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# RESTORE THE POSTGRESQL DATABASE -#================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 - -ynh_psql_test_if_first_run -db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -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 USER RIGHTS -#================================================= # Restore permissions on app files set_permissions #================================================= -# RESTORE SYSTEMD +# RESTORE THE PSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 + +ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql + +#================================================= +# RESTORE SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app-celery.service" ynh_restore_file --origin_path="/etc/systemd/system/$app-beat.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.socket" -systemctl enable $app-celery --quiet -systemctl enable $app-beat --quiet -systemctl enable $app --quiet -systemctl enable $app.socket --quiet +systemctl enable "$app-celery" --quiet +systemctl enable "$app-beat" --quiet +systemctl enable "$app" --quiet +systemctl enable "$app.socket" --quiet +yunohost service add "$app" --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log" #================================================= -# INTEGRATE SERVICE IN YUNOHOST +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -yunohost service add $app --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting systemd services..." --weight=1 - -ynh_systemd_action --service_name=$app.socket --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-celery --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-beat --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_systemd_action --service_name="$app.socket" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 0c48fdc..43effd3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,105 +8,78 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS +# INITIALIZE AND STORE SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +admin_email=$(ynh_user_get_info --username="$admin" --key="mail") -get_app_settings - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_clean_check_starting - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICES #================================================= -ynh_script_progression --message="Stopping systemd services..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd services..." --weight=1 -ynh_systemd_action --service_name=$app.socket --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-beat --action="stop" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-celery --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app.socket" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="/var/log/$app/$app.log" -systemctl disable $app.socket --quiet -systemctl disable $app --quiet -systemctl disable $app-beat --quiet -systemctl disable $app-celery --quiet +systemctl disable "$app.socket" --quiet +systemctl disable "$app" --quiet +systemctl disable "$app-beat" --quiet +systemctl disable "$app-celery" --quiet #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -if [ -z "$datadir" ]; then - datadir=$(ynh_app_setting_get --app=$app --key=data_path) - ynh_app_setting_set --app=$app --key=datadir --value=$datadir - ynh_app_setting_delete --app=$app --key=data_path - ynh_app_setting_delete --app=$app --key=db_pwd - ynh_app_setting_delete --app=$app --key=admin_email +if [ -n "${data_path:-}" ]; then + ynh_app_setting_delete --app="$app" --key=data_path + ynh_app_setting_delete --app="$app" --key=db_pwd + ynh_app_setting_delete --app="$app" --key=admin_email fi -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +if [[ -n "${random_key:-}" ]]; then + secret_key="$random_key" + ynh_app_setting_delete --app="$app" --key=random_key + ynh_app_setting_set --app="$app" --key=secret_key --value="$random_key" +fi -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +if [ -f "$install_dir/requirements.txt" ]; then + mkdir "$install_dir/sources" + # Move to $install_dir/sources + find "$install_dir" -maxdepth 1 -mindepth 1 -not -name sources -exec mv -t "$install_dir/sources" {} + + mv "$install_dir/sources/envs" "$install_dir" +fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=1 +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir/sources" --full_replace=1 - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" -fi +#================================================= +# APP INITIAL CONFIGURATION +#================================================= +ynh_script_progression --message="Adding $app's configuration files..." --weight=1 + +mkdir -p "$env_path" +echo "$admin <$admin_email>" > "$env_path/ADMINS" +echo "None" > "$env_path/BROKER_POOL_LIMIT" +echo "redis://localhost:6379" > "$env_path/BROKER_URL" +echo "postgres://$db_user:$db_pwd@localhost:5432/$db_name" > "$env_path/DATABASE_URL" +echo "False" > "$env_path/DEBUG" +echo "$domain" > "$env_path/DEFAULT_BASE_URL" +echo "$app@$domain" > "$env_path/DEFAULT_FROM_EMAIL" +echo "django.core.mail.backends.console.EmailBackend" > "$env_path/EMAIL_BACKEND" +echo "$data_dir" > "$env_path/MEDIA_ROOT" +echo "$secret_key" > "$env_path/SECRET_KEY" +echo "$app@$domain" > "$env_path/SERVER_EMAIL" set_permissions -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=1 - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC UPGRADE #================================================= # UPDATE VIRTUALENV #================================================= @@ -123,45 +94,36 @@ ynh_script_progression --message="Performing database migrations..." --weight=2 upgrade_db +set_permissions + #================================================= -# SETUP SYSTEMD +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config -ynh_add_systemd_config --service="$app-socket" --template systemd.socket +yunohost service add "$app" --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log" ynh_add_systemd_config --service="$app-celery" --template systemd-celery.service ynh_add_systemd_config --service="$app-beat" --template systemd-beat.service +# Some workaround bc ynh_add_system_config doesn't know sockets +ynh_add_systemd_config --service="$app-socket" --template systemd.socket systemctl disable "$app-socket.service" --quiet mv "/etc/systemd/system/$app-socket.service" "/etc/systemd/system/$app.socket" systemctl daemon-reload --quiet -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Manage podcast subscriptions, and sync them between apps and devices" --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting systemd services..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 -ynh_systemd_action --service_name=$app.socket --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-celery --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name=$app-beat --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app.socket" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app-beat" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/sources/extra_files/app/.gitignore b/sources/extra_files/app/.gitignore deleted file mode 100644 index 783a4ae..0000000 --- a/sources/extra_files/app/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -*.sw[op] diff --git a/sources/patches/app-00-gunicorn.conf.py.patch b/sources/patches/main-00-gunicorn.conf.py.patch similarity index 100% rename from sources/patches/app-00-gunicorn.conf.py.patch rename to sources/patches/main-00-gunicorn.conf.py.patch diff --git a/sources/patches/app-01-settings.py.patch b/sources/patches/main-01-settings.py.patch similarity index 100% rename from sources/patches/app-01-settings.py.patch rename to sources/patches/main-01-settings.py.patch diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..95f32c8 --- /dev/null +++ b/tests.toml @@ -0,0 +1,7 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + test_upgrade_from.8284155ea371f4b8a9f0c333d486c5a2342acfae.name = "2.11.20211020~ynh1"