From d180a4063f91c58db24c5d3b0604fc4d0952a60b Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Mon, 11 Jan 2021 21:44:02 +0100 Subject: [PATCH] Fix --- README.md | 2 +- conf/app.src | 4 +- conf/systemd.service | 4 +- manifest.json | 2 +- scripts/_common.sh | 96 +++++++++++++++++++++++++++++++++++++++++++- scripts/backup | 5 --- scripts/install | 79 +++++++++++++----------------------- scripts/remove | 12 ------ scripts/restore | 19 +++++---- scripts/upgrade | 16 +++++--- scripts/ynh_add_swap | 93 ------------------------------------------ 11 files changed, 151 insertions(+), 181 deletions(-) delete mode 100644 scripts/ynh_add_swap diff --git a/README.md b/README.md index ac592d4..ae85039 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Overview [Misskey](https://join.misskey.page/en/) is a forever evolving, sophisticated microblogging platform that support Fediverse. It provide another flavour to decentralised network. Why don't you take a short break from the hustle and bustle of the city, and dive into a new Internet? -**Shipped version:** 12.47.1 +**Shipped version:** 12.66.0 ## Screenshots diff --git a/conf/app.src b/conf/app.src index 0bcd834..bd824a3 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/syuilo/misskey/archive/12.47.1.tar.gz -SOURCE_SUM=59154273ae1f20187cc69689f4c03eb230c2d3a47e830affb0aaa57b71c49b0b +SOURCE_URL=https://github.com/syuilo/misskey/archive/12.66.0.tar.gz +SOURCE_SUM=bdba1e3c1fd0de1044df068464850c3230c9c7218d8a691493602ab8b5f80f5c SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/systemd.service b/conf/systemd.service index 2d4101f..51357a2 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -4,9 +4,11 @@ Description=__APP__ daemon running [Service] Type=simple User=__APP__ -ExecStart=/usr/local/bin/npm start +Group=__APP__ WorkingDirectory=__FINALPATH__ +Environment="PATH=__ENV_PATH__" Environment="NODE_ENV=production" +ExecStart=__YNH_NPM__ start TimeoutSec=60 StandardOutput=syslog StandardError=syslog diff --git a/manifest.json b/manifest.json index b366c96..68670da 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Microblogging platform", "fr": "Microblogging platform" }, - "version": "12.47.1~ynh1", + "version": "12.66.0~ynh1", "url": "https://join.misskey.page/en/", "license": "AGPL-3.0-or-later", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 0ad4945..5fa2131 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -9,7 +9,7 @@ MEMORY_NEEDED="2560" # dependencies used by the app pkg_dependencies=" build-essential python ffmpeg redis-server redis-tools postgresql postgresql-contrib" -NODEJS_VERSION="12" +nodejs_version=12 #================================================= # PERSONAL HELPERS @@ -22,3 +22,97 @@ NODEJS_VERSION="12" #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +#!/bin/bash + +# Add swap +# +# usage: ynh_add_swap --size=SWAP in Mb +# | arg: -s, --size= - Amount of SWAP to add in Mb. +ynh_add_swap () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=size= ) + local size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local swap_max_size=$(( $size * 1024 )) + + local free_space=$(df --output=avail / | sed 1d) + # Because we don't want to fill the disk with a swap file, divide by 2 the available space. + local usable_space=$(( $free_space / 2 )) + + SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} + + # Swap on SD card only if it's is specified + if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] + then + ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" + return + fi + + # Compare the available space with the size of the swap. + # And set a acceptable size from the request + if [ $usable_space -ge $swap_max_size ] + then + local swap_size=$swap_max_size + elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] + then + local swap_size=$(( $swap_max_size / 2 )) + elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] + then + local swap_size=$(( $swap_max_size / 3 )) + elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] + then + local swap_size=$(( $swap_max_size / 4 )) + else + echo "Not enough space left for a swap file" >&2 + local swap_size=0 + fi + + # If there's enough space for a swap, and no existing swap here + if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] + then + # 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 + dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} + fi + chmod 0600 /swap_$app + # Create the swap + mkswap /swap_$app + # And activate it + swapon /swap_$app + # Then add an entry in fstab to load this swap at each boot. + echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab + fi +} + +ynh_del_swap () { + # If there a swap at this place + if [ -e /swap_$app ] + then + # Clean the fstab + sed -i "/#Swap added by $app/d" /etc/fstab + # Desactive the swap file + swapoff /swap_$app + # And remove it + rm /swap_$app + fi +} + +# Check if the device of the main mountpoint "/" is an SD card +# +# [internal] +# +# return 0 if it's an SD card, else 1 +ynh_is_main_device_a_sd_card () { + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] + then + return 0 + else + return 1 + fi +} \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 9253ced..a64c9b1 100755 --- a/scripts/backup +++ b/scripts/backup @@ -49,17 +49,12 @@ ynh_backup --src_path="$final_path" 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" - #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= diff --git a/scripts/install b/scripts/install index 54ccf55..64397aa 100755 --- a/scripts/install +++ b/scripts/install @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source ynh_add_swap #================================================= # MANAGE SCRIPT FAILURE @@ -67,9 +66,9 @@ ynh_app_setting_set --app=$app --key=port --value=$port #================================================= ynh_script_progression --message="Installing dependencies..." -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" @@ -79,8 +78,8 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st ynh_script_progression --message="Creating a POSTGRESQL database..." # Create postgresql database -db_name="${app}" -db_user=$app +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name db_pwd=$(ynh_string_random --length=8) ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd @@ -123,7 +122,7 @@ ynh_script_progression --message="Configuring nginx web server..." ### `ynh_add_nginx_config` will use the file conf/nginx.conf # Create a dedicated nginx config -ynh_add_nginx_config 'port' +ynh_add_nginx_config #================================================= # CREATE DEDICATED USER @@ -133,56 +132,17 @@ ynh_script_progression --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app - -#================================================= -# SPECIFIC SETUP -#================================================= -# ... -#================================================= - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." - -# Create a dedicated systemd config -ynh_add_systemd_config - - -# Set right permissions for curl install -chown -R $app: $final_path - - -# Remove the public access -if [ $is_public -eq 0 ] -then - ynh_app_setting_delete --app=$app --key=skipped_uris -fi - #================================================= # MODIFY A CONFIG FILE #================================================= -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) +cp -f ../conf/default.yml "$final_path/.config/default.yml" -config="$final_path/.config/default.yml" -cp -f ../conf/default.yml "$config" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target_file="$config" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" - - -#================================================= -# INSTALLING MISKKEY -#================================================= -pushd "$final_path" - yarn add ts-node webpack - NODE_ENV=production yarn build - yarn run init -popd +ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target_file="$final_path/.config/default.yml" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/.config/default.yml" +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/.config/default.yml" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/.config/default.yml" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/.config/default.yml" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -191,6 +151,16 @@ popd # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config" +#================================================= +# INSTALLING MISKKEY +#================================================= + +pushd "$final_path" + ynh_exec_warn_lessyarn add ts-node webpack + ynh_exec_warn_less NODE_ENV=production yarn build + ynh_exec_warn_less yarn run init +popd + #================================================= # GENERIC FINALIZATION #================================================= @@ -200,6 +170,13 @@ ynh_store_file_checksum --file="$config" # Set permissions to app files chown -R $app: $final_path +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1 + +yunohost service add $app --description="A interplanetary blogging platform" --log="/var/log/$app/$app.log" + #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/remove b/scripts/remove index 2be780a..1a9cc3b 100755 --- a/scripts/remove +++ b/scripts/remove @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source ynh_add_swap #================================================= # LOAD SETTINGS @@ -77,20 +76,9 @@ ynh_script_progression --message="Removing nginx web server configuration..." -- # Remove the dedicated nginx config ynh_remove_nginx_config - # Remove swap ynh_del_swap -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - #================================================= # SPECIFIC REMOVE #================================================= diff --git a/scripts/restore b/scripts/restore index 3155710..727741e 100755 --- a/scripts/restore +++ b/scripts/restore @@ -9,7 +9,6 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -source ../settings/scripts/ynh_add_swap #================================================= # MANAGE SCRIPT FAILURE @@ -49,7 +48,10 @@ test ! -d $final_path \ #================================================= # 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 @@ -88,7 +90,6 @@ if [ $total_memory -lt $MEMORY_NEEDED ]; then swap_needed=$(($MEMORY_NEEDED - $total_memory)) fi - #================================================= # SPECIFIC RESTORATION #================================================= @@ -97,8 +98,10 @@ fi ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies + ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" @@ -115,25 +118,26 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= # INSTALLING MISKKEY #================================================= + pushd "$final_path" yarn add ts-node webpack NODE_ENV=production yarn build popd - #================================================= # RESTORE SYSTEMD #================================================= ynh_script_progression --message="Restoring the systemd configuration..." + ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service +systemctl enable $app.service --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "A short description of the app" --log "systemd" --line_match="All workers started" +yunohost service add $app --description "A interplanetary blogging platform" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -142,7 +146,6 @@ ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="All workers started" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 6b34a64..eb19f38 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source ynh_add_swap #================================================= # LOAD SETTINGS @@ -105,8 +104,10 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies + ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= @@ -149,11 +150,14 @@ ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_f #================================================= # Updating process MISSKEY #================================================= + pushd "$final_path" - yarn add ts-node webpack - NODE_ENV=production yarn build + ynh_exec_warn_lessyarn add ts-node webpack + ynh_exec_warn_less NODE_ENV=production yarn build + ynh_exec_warn_less yarn run init popd + #================================================= # SETUP SYSTEMD #================================================= @@ -188,7 +192,7 @@ chown -R $app: $final_path #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app service" ---log_type "systemd" +yunohost service add $app --description "A interplanetary blogging platform" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/ynh_add_swap b/scripts/ynh_add_swap deleted file mode 100644 index 2fd2d8c..0000000 --- a/scripts/ynh_add_swap +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -# Add swap -# -# usage: ynh_add_swap --size=SWAP in Mb -# | arg: -s, --size= - Amount of SWAP to add in Mb. -ynh_add_swap () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [s]=size= ) - local size - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - local swap_max_size=$(( $size * 1024 )) - - local free_space=$(df --output=avail / | sed 1d) - # Because we don't want to fill the disk with a swap file, divide by 2 the available space. - local usable_space=$(( $free_space / 2 )) - - SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} - - # Swap on SD card only if it's is specified - if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] - then - ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" - return - fi - - # Compare the available space with the size of the swap. - # And set a acceptable size from the request - if [ $usable_space -ge $swap_max_size ] - then - local swap_size=$swap_max_size - elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] - then - local swap_size=$(( $swap_max_size / 2 )) - elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] - then - local swap_size=$(( $swap_max_size / 3 )) - elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] - then - local swap_size=$(( $swap_max_size / 4 )) - else - echo "Not enough space left for a swap file" >&2 - local swap_size=0 - fi - - # If there's enough space for a swap, and no existing swap here - if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] - then - # 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 - dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} - fi - chmod 0600 /swap_$app - # Create the swap - mkswap /swap_$app - # And activate it - swapon /swap_$app - # Then add an entry in fstab to load this swap at each boot. - echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab - fi -} - -ynh_del_swap () { - # If there a swap at this place - if [ -e /swap_$app ] - then - # Clean the fstab - sed -i "/#Swap added by $app/d" /etc/fstab - # Desactive the swap file - swapoff /swap_$app - # And remove it - rm /swap_$app - fi -} - -# Check if the device of the main mountpoint "/" is an SD card -# -# [internal] -# -# return 0 if it's an SD card, else 1 -ynh_is_main_device_a_sd_card () { - local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) - - if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] - then - return 0 - else - return 1 - fi -} \ No newline at end of file