1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/distbin_ynh.git synced 2024-09-03 18:26:10 +02:00

Merge pull request #28 from YunoHost-Apps/testing

Several fixes
This commit is contained in:
yalh76 2019-02-09 04:15:45 +01:00 committed by GitHub
commit 153a8cd023
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 97 additions and 37 deletions

View file

@ -26,7 +26,7 @@
Level 3=auto
# Level 4: If the app supports LDAP and SSOwat, turn level 4 to '1' and add a link to an issue or a part of your code to show it.
# If the app does not use LDAP nor SSOwat, and can't use them, turn level 4 to 'na' and explain as well.
# no ldap support
# https://github.com/YunoHost-Apps/distbin_ynh/issues/18
Level 4=na
Level 5=auto
Level 6=auto

14
conf/.env Normal file
View file

@ -0,0 +1,14 @@
# The path to NODEJS
PATH=__NODEJS_PATH__
# The port used by the application
PORT=__PORT__
# The directory where is store the database
DB_DIR=__FINALPATH__/distbin-db
# The external URL
EXTERNAL_URL=https://__DOMAIN_URI__
# The Node Environnement
NODE_ENV=production

View file

@ -6,12 +6,9 @@ After=network.target
Type=simple
User=__APP__
Group=__APP__
Environment="PATH=__NODEJS_PATH__"
Environment="PORT=__PORT__"
Environment="DB_DIR=__FINALPATH__/db"
Environment="NODE_ENV=production"
WorkingDirectory=__FINALPATH__/
ExecStart=/bin/sh -c '__FINALPATH__/node_modules/.bin/ts-node --project __FINALPATH__/tsconfig.json __FINALPATH__/bin/server.ts >> /var/log/__APP__/__APP__.log 2>&1'
EnvironmentFile=__FINALPATH__/.env
WorkingDirectory=__FINALPATH__
ExecStart=/bin/sh -c 'node ./dist/bin/server >> /var/log/__APP__/__APP__.log 2>&1'
[Install]
WantedBy=multi-user.target

View file

@ -6,7 +6,7 @@
"en": "Distributed pastebin with ActivityPub.",
"fr": "Pastebin distribué utilisant le protocole ActivityPub."
},
"version": "1.0~ynh3",
"version": "1.0~ynh4",
"url": "https://example.com",
"license": "Apache-2.0",
"maintainer": {

View file

@ -90,9 +90,31 @@ fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# ...
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#=================================================
# MODIFY A CONFIG FILE
#=================================================
# Change the URL in the configuration file
ynh_replace_string "EXTERNAL_URL=.*" "EXTERNAL_URL=https://$new_domain$new_path" "$final_path/.env"
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/.env"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/.env"
#=================================================
# START SERVICE
#=================================================
ynh_systemd_action --action=start --service_name=$app
#=================================================
# GENERIC FINALISATION
#=================================================

View file

@ -16,6 +16,7 @@ source /usr/share/yunohost/helpers
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
read -p "Press any key..."
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
@ -97,6 +98,7 @@ ynh_app_setting_set $app port $port
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
ynh_install_app_dependencies ca-certificates
ynh_install_nodejs 8
#=================================================
@ -176,7 +178,7 @@ chown -R "$app":"$app" "/var/log/$app"
# CREATE DB FOLDER
#=================================================
mkdir -p "$final_path/db"
mkdir -p "$final_path/distbin-db"
#=================================================
# MAKE SETUP
@ -185,12 +187,16 @@ mkdir -p "$final_path/db"
chown -R "$app":"$app" "$final_path"
pushd $final_path
ynh_use_nodejs
sudo -u $app env PATH=$PATH:$nodejs_path npm add hoek@^4.2.1 --save --production
sudo -u $app env PATH=$PATH:$nodejs_path npm install ts-node
sudo -u $app env PATH=$PATH:$nodejs_path npm install --production
sudo -u $app env PATH=$PATH:$nodejs_path npm audit fix
sudo -u $app env PATH=$PATH npm install --ignore-scripts
sudo -u $app env PATH=$PATH npm run build
cp package* dist/
popd
pushd $final_path/dist
sudo -u $app env PATH=$PATH npm install --ignore-scripts --production
popd
#=================================================
# SETUP SYSTEMD
#=================================================
@ -207,8 +213,6 @@ popd
### - And the section "SETUP SYSTEMD" in the upgrade script
# Create a dedicated systemd config
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service"
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_add_systemd_config
#=================================================
@ -247,7 +251,12 @@ ynh_add_systemd_config
### `ynh_replace_string` is used to replace a string in a file.
### (It's compatible with sed regular expressions syntax)
#ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE"
cp "../conf/.env" "$final_path/.env"
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "$final_path/.env"
ynh_replace_string "__PORT__" "$port" "$final_path/.env"
ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "$final_path/.env"
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/.env"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
@ -258,7 +267,7 @@ ynh_add_systemd_config
### you can make a backup of this file before modifying it again if the admin had modified it.
# Calculate and store the config file checksum into the app settings
#ynh_store_file_checksum "$final_path/package.json"
ynh_store_file_checksum "$final_path/.env"
#=================================================
# GENERIC FINALIZATION
@ -271,7 +280,7 @@ ynh_add_systemd_config
### that really need such authorization.
# Set permissions to app files
#chown -R root: $final_path
chown -R "$app":"$app" "$final_path"
#=================================================
# SETUP LOGROTATE

View file

@ -93,7 +93,7 @@ chown -R $app:$app /var/log/$app
#=================================================
# Define and install dependencies
#ynh_install_app_dependencies
ynh_install_app_dependencies ca-certificates
ynh_install_nodejs 8
#=================================================

View file

@ -64,12 +64,6 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#=================================================
# CHECK THE PATH
#=================================================
@ -77,6 +71,12 @@ ynh_systemd_action --action=stop --service_name=$app
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
@ -101,7 +101,7 @@ ynh_add_nginx_config
# UPGRADE DEPENDENCIES
#=================================================
#ynh_install_app_dependencies deb1 deb2
ynh_install_app_dependencies ca-certificates
ynh_install_nodejs 8
#=================================================
@ -120,13 +120,15 @@ ynh_system_user_create "$app" "$final_path"
#=================================================
# SPECIFIC UPGRADE
#=================================================
#=================================================
# CREATE DB FOLDER
#=================================================
mkdir -p "$final_path/db"
DIRECTORY="$final_path/db"
#Move old db
if [ -d "$DIRECTORY" ]; then
mv "$final_path/db" "$final_path/distbin-db"
fi
#=================================================
# MAKE INSTALL
@ -135,16 +137,34 @@ mkdir -p "$final_path/db"
chown -R "$app":"$app" "$final_path"
pushd $final_path
ynh_use_nodejs
sudo -u $app env PATH=$PATH:$nodejs_path npm update --production
sudo -u $app env PATH=$PATH:$nodejs_path npm install --production
sudo -u $app env PATH=$PATH:$nodejs_path npm audit fix
sudo -u $app env PATH=$PATH npm install --ignore-scripts
sudo -u $app env PATH=$PATH npm run build
cp package* dist/
popd
pushd $final_path/dist
sudo -u $app env PATH=$PATH npm install --ignore-scripts --production
popd
#=================================================
# 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 "../conf/.env" "$final_path/.env"
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "$final_path/.env"
ynh_replace_string "__PORT__" "$port" "$final_path/.env"
ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "$final_path/.env"
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/.env"
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
#ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE"
ynh_backup_if_checksum_is_different "$final_path/.env"
# Recalculate and store the checksum of the file for the next upgrade.
#ynh_store_file_checksum "$final_path/CONFIG_FILE"
ynh_store_file_checksum "$final_path/.env"
#=================================================
# SETUP LOGROTATE
@ -158,8 +178,6 @@ ynh_use_logrotate --non-append
#=================================================
# Create a dedicated systemd config
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service"
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_add_systemd_config
#=================================================