diff --git a/conf/.env b/conf/.env new file mode 100644 index 0000000..f94c4e5 --- /dev/null +++ b/conf/.env @@ -0,0 +1,14 @@ +# The path to NODEJS +PATH=__NODEJS_PATH__ + +# URL of the mongodb +MONGO_URL=mongodb://127.0.0.1:27017/__DB_NAME__ + +# Root URL +ROOT_URL=https://__DOMAIN_URI__ + +#Port +PORT=__PORT__ + +# The Node Environnement +NODE_ENV=production diff --git a/conf/systemd.service b/conf/systemd.service index 0fb4618..5abbcbf 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,10 +7,7 @@ After=network.target mongodb.service Type=simple User=__APP__ Group=__APP__ -Environment="PATH=__ENV_PATH__" -Environment=NODE_ENV=production -Environment=MONGO_URL=mongodb://127.0.0.1:27017/__DB_NAME__ -Environment=ROOT_URL=https://__DOMAIN_URI__ PORT=__PORT__ +EnvironmentFile=__FINALPATH__/.env WorkingDirectory=__FINALPATH__ ExecStart=/opt/node_n/bin/node __FINALPATH__/main.js Restart=on-failure diff --git a/scripts/install b/scripts/install index 90daf64..29f7d26 100755 --- a/scripts/install +++ b/scripts/install @@ -194,13 +194,32 @@ ynh_print_info "Configuring a systemd service..." ### - And the section "SETUP SYSTEMD" in the upgrade script # Create a dedicated systemd config -ynh_print_info "Adding wekan systemd service ..." -ynh_replace_string "__ENV_PATH__" "$nodejs_path" "../conf/systemd.service" -ynh_replace_string "__DB_NAME__" "$db_name" "../conf/systemd.service" -ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "../conf/systemd.service" -ynh_replace_string "__PORT__" "$port" "../conf/systemd.service" ynh_add_systemd_config +#================================================= +# 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 "__DB_NAME__" "$db_name" "$final_path/.env" +ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "$final_path/.env" +ynh_replace_string "__PORT__" "$port" "$final_path/.env" + +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= + +### `ynh_store_file_checksum` is used to store the checksum of a file. +### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, +### 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/.env" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 4f48cfa..6240306 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -69,13 +69,17 @@ fi if ynh_version_gt "0.77-2" "${previous_version}" ; then ynh_install_nodejs 8.9.3 - ynh_use_nodejs + ynh_use_nodejs # Create a dedicated systemd config - ynh_replace_string "__ENV_PATH__" "$nodejs_path" "../conf/systemd.service" - ynh_replace_string "__DB_NAME__" "$db_name" "../conf/systemd.service" - ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "../conf/systemd.service" - ynh_replace_string "__PORT__" "$port" "../conf/systemd.service" ynh_add_systemd_config + # Create a dedicated .env config + ynh_backup_if_checksum_is_different "$final_path/.env" + cp "../conf/.env" "$final_path/.env" + ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "$final_path/.env" + ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/.env" + ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "$final_path/.env" + ynh_replace_string "__PORT__" "$port" "$final_path/.env" + ynh_store_file_checksum "$final_path/.env" fi if ynh_version_gt "1.07~ynh2" "${previous_version}" ; then