diff --git a/conf/05-flohmarkt.ini b/conf/05-flohmarkt.ini index c85771c..206698c 100644 --- a/conf/05-flohmarkt.ini +++ b/conf/05-flohmarkt.ini @@ -1,5 +1,3 @@ [chttpd] ; prevent non admin users to be able to access the list of all databases admin_only_all_dbs = true - -; port = __##PORT_COUCHDB__ diff --git a/conf/flohmarkt.conf b/conf/flohmarkt.conf index a32025b..14daab3 100644 --- a/conf/flohmarkt.conf +++ b/conf/flohmarkt.conf @@ -10,7 +10,6 @@ UseHttps = 0 Host = 127.0.0.1 User = __APP__ Password = __PASSWORD_COUCHDB_FLOHMARKT__ -# Port = __##PORT_COUCHDB__ Port = 5984 Database = __APP__ diff --git a/conf/systemd.service b/conf/systemd.service index 79938cb..2820248 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -9,6 +9,8 @@ Group=__APP__ WorkingDirectory=__FLOHMARKT_APP_DIR__ Environment="VENV_DIR=__FLOHMARKT_VENV_DIR__" ExecStart=/bin/bash -c "__FLOHMARKT_VENV_DIR__/bin/uvicorn --host 127.0.0.1 --port __PORT__ flohmarkt.web:start 2>&1 | /usr/bin/ts '%%Y-%%m-%%d %%H:%%M:%%S'" +Restart=on-failure +RestartSec=5s # nicer logfile naming https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/38 StandardOutput=append:__FLOHMARKT_LOGFILE__ StandardError=inherit diff --git a/scripts/_common.sh b/scripts/_common.sh index 0d5b70d..e5b93ce 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -53,14 +53,49 @@ flohmarkt_ynh_set_permission() { chmod g-w,o-rwx -R "$flohmarkt_install" } +# start flohmarkt service flohmarkt_ynh_start_service() { ynh_systemd_action --service_name=$flohmarkt_filename --action="start" \ --line_match='INFO: *Application startup complete.' --log_path="$flohmarkt_logfile" \ --timeout=30 } +# stop flohmarkt service flohmarkt_ynh_stop_service() { - ynh_systemd_action --service_name=$app --action="stop" + ynh_systemd_action --service_name=$flohmarkt_filename --action="stop" +} + +# start couchdb and wait for success +flohmarkt_ynh_start_couchdb() { + ynh_systemd_action --service_name=couchdb --action="start" --timeout=30 \ + --log_path="/var/log/couchdb/couchdb.log" \ + --line_match='Apache CouchDB has started on http://127.0.0.1' +} + +# stop couchdb +flohmarkt_ynh_stop_couchdb() { + ynh_systemd_action --service_name=couchdb --action="stop" --timeout=30 \ + --log_path="/var/log/couchdb/couchdb.log" \ + --line_match='SIGTERM received - shutting down' +} + +# install or upgrade couchdb +flohmarkt_ynh_up_inst_couchdb() { + echo "\ + couchdb couchdb/mode select standalone + couchdb couchdb/mode seen true + couchdb couchdb/bindaddress string 127.0.0.1 + couchdb couchdb/bindaddress seen true + couchdb couchdb/cookie string $couchdb_magic_cookie + couchdb couchdb/adminpass password $password_couchdb_admin + couchdb couchdb/adminpass seen true + couchdb couchdb/adminpass_again password $password_couchdb_admin + couchdb couchdb/adminpass_again seen true" | debconf-set-selections + DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb + ynh_install_extra_app_dependencies \ + --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \ + --key="https://couchdb.apache.org/repo/keys.asc" \ + --package="couchdb" } # create venv diff --git a/scripts/install b/scripts/install index 971c760..eb7fd65 100755 --- a/scripts/install +++ b/scripts/install @@ -33,22 +33,11 @@ ynh_script_progression --message="Installing CouchDB..." --weight=60 couchdb_magic_cookie=$(ynh_string_random --length=23 --filter='A-Za-z0-9_') ynh_app_setting_set --app=$app --key=couchdb_magic_cookie --value="$couchdb_magic_cookie" -echo "\ -couchdb couchdb/mode select standalone -couchdb couchdb/mode seen true -couchdb couchdb/bindaddress string 127.0.0.1 -couchdb couchdb/bindaddress seen true -couchdb couchdb/cookie string $couchdb_magic_cookie -couchdb couchdb/adminpass password $password_couchdb_admin -couchdb couchdb/adminpass seen true -couchdb couchdb/adminpass_again password $password_couchdb_admin -couchdb couchdb/adminpass_again seen true" | debconf-set-selections -DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb +# update couchdb dpkg +flohmarkt_ynh_up_inst_couchdb -ynh_install_extra_app_dependencies \ - --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \ - --key="https://couchdb.apache.org/repo/keys.asc" \ - --package="couchdb" +# stop couchdb +flohmarkt_ynh_stop_couchdb # add couchdb configuration ynh_script_progression --message="Adding a configuration file..." --weight=2 @@ -58,8 +47,7 @@ chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini # restart couchdb to pick up changes -systemctl restart couchdb -systemctl status couchdb +flohmarkt_ynh_start_couchdb # get flohmarkt # suspecting that this deletes all other sources for YNH_APP_ID diff --git a/scripts/restore b/scripts/restore index 2c27d3f..9921e58 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,26 +10,8 @@ ynh_restore_file --origin_path="/var/lib/couchdb" # reinstall couchdb ynh_script_progression --message="Reinstalling couchdb..." --weight=40 - -echo "\ -couchdb couchdb/mode select standalone -couchdb couchdb/mode seen true -couchdb couchdb/bindaddress string 127.0.0.1 -couchdb couchdb/bindaddress seen true -couchdb couchdb/cookie string $couchdb_magic_cookie -couchdb couchdb/adminpass password $password_couchdb_admin -couchdb couchdb/adminpass seen true -couchdb couchdb/adminpass_again password $password_couchdb_admin -couchdb couchdb/adminpass_again seen true" | debconf-set-selections -DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb - -ynh_install_extra_app_dependencies \ - --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \ - --key="https://couchdb.apache.org/repo/keys.asc" \ - --package="couchdb" - -# stop couchdb -systemctl stop couchdb +flohmarkt_ynh_up_inst_couchdb +flohmarkt_ynh_stop_couchdb # add couchdb configuration ynh_script_progression --message="Adding a configuration file..." --weight=2 @@ -38,8 +20,7 @@ chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini # start couchdb -systemctl start couchdb -systemctl status couchdb +flohmarkt_ynh_start_couchdb # RESTORE THE APP MAIN DIR ynh_script_progression --message="Restoring the app main directory..." --weight=10 diff --git a/scripts/upgrade b/scripts/upgrade index d20d8bc..76e394f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -17,7 +17,7 @@ ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5 # stop flohmarkt flohmarkt_ynh_stop_service # stop couchdb -ynh_systemd_action --service_name=couchdb --action="stop" +flohmarkt_ynh_stop_couchdb # Upgrade ynh4 → ynh5, change of paths and filenames # https://matrix.to/#/!PauySEslPVuJCJCwlZ:matrix.org/$auU_rSL6MACt9wkyFGlCQbO8ivFlU0ztYW74TimZdcM?via=matrix.org&via=aria-net.org&via=sans-nuage.fr @@ -30,21 +30,11 @@ fi # upgrade couchdb ynh_script_progression --message="Upgrading CouchDB..." --weight=50 -echo "\ -couchdb couchdb/mode select standalone -couchdb couchdb/mode seen true -couchdb couchdb/bindaddress string 127.0.0.1 -couchdb couchdb/bindaddress seen true -couchdb couchdb/cookie string $couchdb_magic_cookie -couchdb couchdb/adminpass password $password_couchdb_admin -couchdb couchdb/adminpass seen true -couchdb couchdb/adminpass_again password $password_couchdb_admin -couchdb couchdb/adminpass_again seen true" | debconf-set-selections -DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb -ynh_install_extra_app_dependencies \ - --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \ - --key="https://couchdb.apache.org/repo/keys.asc" \ - --package="couchdb" +flohmarkt_ynh_up_inst_couchdb + +# stop couchdb +ynh_script_progression --message="Stop couchdb before updating configuration file..." --weight=1 +flohmarkt_ynh_stop_couchdb # upgrade couchdb config ynh_script_progression --message="Updating couchdb configuration file..." --weight=1 @@ -52,10 +42,9 @@ ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini -# start couchdb to pick up changes +# start couchdb ynh_script_progression --message="Starting couchdb..." --weight=1 -ynh_systemd_action --service_name=couchdb --action="start" -systemctl status couchdb +flohmarkt_ynh_start_couchdb # install upgrade for flohmarkt ynh_script_progression --message="Upgrading flohmarkt..." --weight=4