diff --git a/check_process b/check_process index b16e300..fc45223 100644 --- a/check_process +++ b/check_process @@ -19,7 +19,7 @@ setup_public=1 upgrade=1 backup_restore=1 - multi_instance=1 + multi_instance=0 port_already_use=0 change_url=1 ;;; Options diff --git a/conf/systemd.service b/conf/systemd.service index 7b541f4..33cf560 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,5 +1,5 @@ [Unit] -Description=Small description of the service +Description=AI-Powered Photos App for the Decentralized Web After=network.target [Service] diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md index 27c354d..d3a719c 100644 --- a/doc/DISCLAIMER.md +++ b/doc/DISCLAIMER.md @@ -1,4 +1,6 @@ * Known limitations: + * Although reaching level 7, Photoprism hasn't yet been extensively tested in real conditions + * Please use with **extreme care** if you install it on a test server ! * Not tested yet with AMD architecture * Photoprism currently supports only one user. OIDC should be supported within a few months * Photoprism requires an important amount of RAM and disk to install or to work properly diff --git a/manifest.json b/manifest.json index 7173a9f..121a29c 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "AI-Powered Photos App for the Decentralized Web", "fr": "Gestion de photos en ligne" }, - "version": "2022.28.05~ynh1", + "version": "2022.05.28~ynh2", "url": "photoprism.app", "upstream": { "license": "AGPL-3.0-only", diff --git a/scripts/_common.sh b/scripts/_common.sh index 061b880..7433624 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,7 @@ # Tag name of the installed version PHOTOPRISM_VERSION="220528-efb5d710" +MEMORY_NEEDED="3000" NODEJS_VERSION=14 GO_VERSION="1.18" diff --git a/scripts/backup b/scripts/backup index 99c594d..444217b 100755 --- a/scripts/backup +++ b/scripts/backup @@ -28,10 +28,16 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app=$app --key=final_path) 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) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +language_key=$(ynh_app_setting_get --app=$app --key=language) datadir=$(ynh_app_setting_get --app=$app --key=datadir) +port=$(ynh_app_setting_get --app=$app --key=port) +password=$(ynh_app_setting_get --app=$app --key=password) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -70,20 +76,18 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/logrotate.d/$app" +#================================================= +# BACKUP LOGS +#================================================= + +ynh_backup --src_path="/var/log/$app/$app.log" + #================================================= # BACKUP SYSTEMD #================================================= ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# BACKUP VARIOUS FILES -#================================================= - -ynh_backup --src_path="/etc/cron.d/$app" - -ynh_backup --src_path="/etc/$app/" - #================================================= # BACKUP THE MYSQL DATABASE #================================================= diff --git a/scripts/change_url b/scripts/change_url index 9dd70d8..2ecbf05 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -30,9 +30,13 @@ ynh_script_progression --message="Loading installation settings..." --time --wei final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Add settings here as needed by your application -#db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#db_user=$db_name -#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +language_key=$(ynh_app_setting_get --app=$app --key=language) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) +port=$(ynh_app_setting_get --app=$app --key=port) +password=$(ynh_app_setting_get --app=$app --key=password) #================================================= # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP diff --git a/scripts/install b/scripts/install index c1c40be..72d1298 100755 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ source _common.sh source ynh_install_go +source ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -59,6 +60,7 @@ ynh_script_progression --message="Storing installation settings..." --time --wei 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=language --value=$language_key +ynh_app_setting_set --app=$app --key=password --value=$password #================================================= # STANDARD MODIFICATIONS @@ -84,6 +86,22 @@ ynh_install_nodejs --nodejs_version=$NODEJS_VERSION 2>&1 # Install go ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION +#================================================= +# ADD SWAP IF NEEDED +#================================================= +ynh_script_progression --message="Adding swap is needed..." + +total_memory=$(ynh_get_ram --total) +swap_needed=0 + +if [ $total_memory -lt $MEMORY_NEEDED ]; then + # Need a minimum of 2.5Go of memory + swap_needed=$(($MEMORY_NEEDED - $total_memory)) +fi + +ynh_script_progression --message="Adding $swap_needed Mo to swap..." +ynh_add_swap --size=$swap_needed + #================================================= # CREATE DEDICATED USER #================================================= @@ -147,7 +165,7 @@ pushd "$final_path" # Setup tensorflow library ./scripts/dist/install-tensorflow.sh # Setup node environment - export NODE_OPTIONS=--max_old_space_size=512 + export NODE_OPTIONS=--max_old_space_size=1024 # Build server from source ynh_use_nodejs env "$ynh_node_load_PATH" npm install -g npm @@ -163,9 +181,8 @@ ynh_script_progression --message="Creating a data directory..." --time --weight= datadir=/home/yunohost.app/$app ynh_app_setting_set --app=$app --key=datadir --value=$datadir -mkdir -p $datadir -mkdir "$datadir/assets/" -mv "$final_path/build/assets/"* "$datadir/assets/" +mkdir -p "$datadir/assets/" +rsync -a "$final_path/build/assets/" "$datadir/assets/" chmod 750 "$datadir" chmod -R o-rwx "$datadir" diff --git a/scripts/remove b/scripts/remove index b4c79e2..9a55410 100755 --- a/scripts/remove +++ b/scripts/remove @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -17,11 +18,15 @@ ynh_script_progression --message="Loading installation settings..." --time --wei app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name -final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +language_key=$(ynh_app_setting_get --app=$app --key=language) datadir=$(ynh_app_setting_get --app=$app --key=datadir) +port=$(ynh_app_setting_get --app=$app --key=port) +password=$(ynh_app_setting_get --app=$app --key=password) #================================================= # STANDARD REMOVE @@ -118,6 +123,9 @@ ynh_secure_remove --file="/etc/cron.d/$app" # Remove the log files ynh_secure_remove --file="/var/log/$app" +# Remove swap +ynh_del_swap + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index c34fa67..9c420a5 100755 --- a/scripts/restore +++ b/scripts/restore @@ -8,6 +8,7 @@ # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -33,7 +34,11 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +language_key=$(ynh_app_setting_get --app=$app --key=language) datadir=$(ynh_app_setting_get --app=$app --key=datadir) +port=$(ynh_app_setting_get --app=$app --key=port) +password=$(ynh_app_setting_get --app=$app --key=password) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -84,14 +89,9 @@ ynh_script_progression --message="Restoring the data directory..." --time --weig ynh_restore_file --origin_path="$datadir" --not_mandatory -mkdir -p $datadir +mkdir -p "$datadir/assets/" +rsync -a "$final_path/build/assets/" "$datadir/assets/" -# FIXME: this should be managed by the core in the future -# Here, as a packager, you may have to tweak the ownerhsip/permissions -# such that the appropriate users (e.g. maybe www-data) can access -# files in some cases. -# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - -# this will be treated as a security issue. chmod 750 "$datadir" chmod -R o-rwx "$datadir" chown -R $app:www-data "$datadir" @@ -106,6 +106,22 @@ ynh_script_progression --message="Reinstalling dependencies..." --time --weight= # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +#================================================= +# ADD SWAP IF NEEDED +#================================================= +ynh_script_progression --message="Adding swap is needed..." + +total_memory=$(ynh_get_ram --total) +swap_needed=0 + +if [ $total_memory -lt $MEMORY_NEEDED ]; then + # Need a minimum of 2.5Go of memory + swap_needed=$(($MEMORY_NEEDED - $total_memory)) +fi + +ynh_script_progression --message="Adding $swap_needed Mo to swap..." +ynh_add_swap --size=$swap_needed + #================================================= # RESTORE THE MYSQL DATABASE #================================================= @@ -115,15 +131,6 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql -#================================================= -# RESTORE VARIOUS FILES -#================================================= -ynh_script_progression --message="Restoring various files..." --time --weight=1 - -ynh_restore_file --origin_path="/etc/cron.d/$app" - -ynh_restore_file --origin_path="/etc/$app/" - #================================================= # RESTORE SYSTEMD #================================================= @@ -139,6 +146,13 @@ ynh_script_progression --message="Restoring the logrotate configuration..." --ti ynh_restore_file --origin_path="/etc/logrotate.d/$app" +#================================================= +# RESTORE THE LOGS +#================================================= +ynh_script_progression --message="Restoring the logs..." --weight=1 + +ynh_restore_file --origin_path="/var/log/$app/$app.log" + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 639a28d..7f2e5f9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,6 +8,7 @@ source _common.sh source ynh_install_go +source ynh_add_swap source /usr/share/yunohost/helpers #================================================= @@ -19,9 +20,14 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -language=$(ynh_app_setting_get --app=$app --key=language) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +language_key=$(ynh_app_setting_get --app=$app --key=language) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) +port=$(ynh_app_setting_get --app=$app --key=port) +password=$(ynh_app_setting_get --app=$app --key=password) #================================================= # CHECK VERSION @@ -104,6 +110,22 @@ ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 ynh_install_app_dependencies $pkg_dependencies +#================================================= +# ADD SWAP IF NEEDED +#================================================= +ynh_script_progression --message="Adding swap is needed..." + +total_memory=$(ynh_get_ram --total) +swap_needed=0 + +if [ $total_memory -lt $MEMORY_NEEDED ]; then + # Need a minimum of 2.5Go of memory + swap_needed=$(($MEMORY_NEEDED - $total_memory)) +fi + +ynh_script_progression --message="Adding $swap_needed Mo to swap..." +ynh_add_swap --size=$swap_needed + #================================================= # BUILD PHOTOPRISM @@ -118,11 +140,14 @@ pushd "$final_path" export GOBIN=$GOPATH/bin # Setup tensorflow library ./scripts/dist/install-tensorflow.sh + # Remove the former build file + ynh_secure_remove --file="$final_path/build" # Setup node environment export NODE_OPTIONS=--max_old_space_size=1024 # Build server from source - ynh_secure_remove --file="$final_path/build" - make all install DESTDIR=$final_path/build 2>&1 + ynh_use_nodejs + env "$ynh_node_load_PATH" npm install -g npm + env "$ynh_node_load_PATH" make dep-tensorflow dep-js dep-go build-js install DESTDIR=$final_path/build 2>&1 ynh_secure_remove --file="$final_path/go" popd @@ -131,9 +156,7 @@ popd #================================================= ynh_script_progression --message="Updating data directory..." --time --weight=1 -ynh_secure_remove --file="$datadir/assets" -mkdir "$datadir/assets/" -mv "$final_path/build/assets/"* "$datadir/assets/" +rsync -a "$final_path/build/assets/" "$datadir/assets/" chmod 750 "$datadir" chmod -R o-rwx "$datadir" diff --git a/scripts/ynh_add_swap b/scripts/ynh_add_swap index 83e11f5..2fd2d8c 100644 --- a/scripts/ynh_add_swap +++ b/scripts/ynh_add_swap @@ -51,7 +51,6 @@ ynh_add_swap () { # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case if ! fallocate -l ${swap_size}K /swap_$app then - echo "I'm also in !" dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} fi chmod 0600 /swap_$app