mirror of
https://github.com/YunoHost-Apps/distbin_ynh.git
synced 2024-09-03 18:26:10 +02:00
Merge pull request #24 from YunoHost-Apps/env
Moving environment variable from systemd to .env file
This commit is contained in:
commit
cf0c554038
4 changed files with 45 additions and 24 deletions
14
conf/.env
Normal file
14
conf/.env
Normal 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__/db
|
||||||
|
|
||||||
|
# The external URL
|
||||||
|
EXTERNAL_URL=https://__DOMAIN_URI__
|
||||||
|
|
||||||
|
# The Node Environnement
|
||||||
|
NODE_ENV=production
|
|
@ -6,11 +6,7 @@ After=network.target
|
||||||
Type=simple
|
Type=simple
|
||||||
User=__APP__
|
User=__APP__
|
||||||
Group=__APP__
|
Group=__APP__
|
||||||
Environment="PATH=__NODEJS_PATH__"
|
EnvironmentFile=__FINALPATH__/.env
|
||||||
Environment="PORT=__PORT__"
|
|
||||||
Environment="DB_DIR=__FINALPATH__/db"
|
|
||||||
Environment="EXTERNAL_URL=https://__DOMAIN_URI__"
|
|
||||||
Environment="NODE_ENV=production"
|
|
||||||
WorkingDirectory=__FINALPATH__/
|
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'
|
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'
|
||||||
|
|
||||||
|
|
|
@ -207,9 +207,6 @@ popd
|
||||||
### - And the section "SETUP SYSTEMD" in the upgrade script
|
### - And the section "SETUP SYSTEMD" in the upgrade script
|
||||||
|
|
||||||
# Create a dedicated systemd config
|
# Create a dedicated systemd config
|
||||||
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service"
|
|
||||||
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
|
||||||
ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "../conf/systemd.service"
|
|
||||||
ynh_add_systemd_config
|
ynh_add_systemd_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -248,7 +245,12 @@ ynh_add_systemd_config
|
||||||
### `ynh_replace_string` is used to replace a string in a file.
|
### `ynh_replace_string` is used to replace a string in a file.
|
||||||
### (It's compatible with sed regular expressions syntax)
|
### (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
|
# STORE THE CONFIG FILE CHECKSUM
|
||||||
|
@ -259,7 +261,7 @@ ynh_add_systemd_config
|
||||||
### you can make a backup of this file before modifying it again if the admin had modified it.
|
### 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
|
# 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
|
# GENERIC FINALIZATION
|
||||||
|
@ -272,7 +274,7 @@ ynh_add_systemd_config
|
||||||
### that really need such authorization.
|
### that really need such authorization.
|
||||||
|
|
||||||
# Set permissions to app files
|
# Set permissions to app files
|
||||||
#chown -R root: $final_path
|
chown -R "$app":"$app" "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
|
|
|
@ -64,12 +64,6 @@ ynh_clean_setup () {
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# STOP SERVICE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_systemd_action --action=stop --service_name=$app
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK THE PATH
|
# CHECK THE PATH
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -77,6 +71,12 @@ ynh_systemd_action --action=stop --service_name=$app
|
||||||
# Normalize the URL path syntax
|
# Normalize the URL path syntax
|
||||||
path_url=$(ynh_normalize_url_path $path_url)
|
path_url=$(ynh_normalize_url_path $path_url)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STOP SERVICE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_systemd_action --action=stop --service_name=$app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD UPGRADE STEPS
|
# STANDARD UPGRADE STEPS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -120,8 +120,6 @@ ynh_system_user_create "$app" "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC UPGRADE
|
# SPECIFIC UPGRADE
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE DB FOLDER
|
# CREATE DB FOLDER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -140,11 +138,25 @@ pushd $final_path
|
||||||
sudo -u $app env PATH=$PATH:$nodejs_path npm audit fix
|
sudo -u $app env PATH=$PATH:$nodejs_path npm audit fix
|
||||||
popd
|
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.
|
### 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.
|
### 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.
|
# 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
|
# SETUP LOGROTATE
|
||||||
|
@ -158,9 +170,6 @@ ynh_use_logrotate --non-append
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Create a dedicated systemd config
|
# Create a dedicated systemd config
|
||||||
ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "../conf/systemd.service"
|
|
||||||
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
|
|
||||||
ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "../conf/systemd.service"
|
|
||||||
ynh_add_systemd_config
|
ynh_add_systemd_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue