From 28d6e0d5cdfb3d5a4491c961cb1ccd43c789819d Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sat, 23 May 2020 09:14:00 +0200 Subject: [PATCH] move to postesql --- conf/.sequelizerc.example | 2 +- conf/config.json.example | 4 ++-- conf/systemd.service | 2 +- manifest.json | 3 +-- scripts/_common.sh | 2 +- scripts/backup | 4 ++-- scripts/change_url | 6 +++--- scripts/install | 12 +++++++++--- scripts/remove | 11 +++++------ scripts/restore | 13 +++++++------ scripts/upgrade | 10 +++------- 11 files changed, 35 insertions(+), 34 deletions(-) diff --git a/conf/.sequelizerc.example b/conf/.sequelizerc.example index 29b59f2..45ef120 100644 --- a/conf/.sequelizerc.example +++ b/conf/.sequelizerc.example @@ -4,5 +4,5 @@ module.exports = { 'config': path.resolve('config.json'), 'migrations-path': path.resolve('lib', 'migrations'), 'models-path': path.resolve('lib', 'models'), - 'url': 'mysql://__DB_USER__:__DB_PASS__@localhost:3306/__DB_NAME__' + 'url': 'postgres://__DB_USER__:__DB_PASS__@localhost:5432/__DB_NAME__' } diff --git a/conf/config.json.example b/conf/config.json.example index 52a4cd3..28b8bdf 100644 --- a/conf/config.json.example +++ b/conf/config.json.example @@ -27,8 +27,8 @@ "password": "__DB_PASS__", "database": "__DB_NAME__", "host": "localhost", - "port": "3306", - "dialect": "mysql" + "port": "5432", + "dialect": "postgres" } } } \ No newline at end of file diff --git a/conf/systemd.service b/conf/systemd.service index d7bec22..c7b91d0 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,7 +1,7 @@ [Unit] Description=__APP__: collaborative Markdown notes After=network.target -After=mysql.service +After=postgresql.service [Service] Type=simple diff --git a/manifest.json b/manifest.json index 37d25be..ddd9f95 100644 --- a/manifest.json +++ b/manifest.json @@ -17,8 +17,7 @@ }, "multi_instance": true, "services": [ - "nginx", - "mysql" + "nginx" ], "arguments": { "install": [{ diff --git a/scripts/_common.sh b/scripts/_common.sh index 53e412e..b113120 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="apt-transport-https" +pkg_dependencies="postgresql apt-transport-https" nodejs_version="10" diff --git a/scripts/backup b/scripts/backup index 5dff667..1033992 100644 --- a/scripts/backup +++ b/scripts/backup @@ -50,11 +50,11 @@ ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# BACKUP THE MYSQL DATABASE +# BACKUP THE DATABASE #================================================= ynh_print_info --message="Backing up the database..." -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db --database="$db_name" > db.sql #================================================= # SPECIFIC BACKUP diff --git a/scripts/change_url b/scripts/change_url index fb272a3..5919876 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -31,7 +31,7 @@ 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_user=$(ynh_app_setting_get --app=$app --key=db_user) db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) #================================================= @@ -74,7 +74,7 @@ fi #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # MODIFY URL IN NGINX CONF @@ -112,7 +112,7 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server listening" +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="HTTP Server listening" #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index 050bd6a..4862ca2 100644 --- a/scripts/install +++ b/scripts/install @@ -39,7 +39,7 @@ final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" # Register (book) web path -ynh_webpath_register "$app" "$domain" $path_url +ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url" #================================================= # FIND AND OPEN A PORT @@ -68,7 +68,7 @@ ynh_script_progression --message="Installing dependencies..." --weight=20 ynh_install_app_dependencies $pkg_dependencies # Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version" # Install Yarn ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" @@ -80,8 +80,14 @@ ynh_script_progression --message="Creating a database..." --weight=2 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name +db_pwd=$(ynh_string_random --length=30) + +ynh_app_setting_set --app="$app" --key="db_pwd" --value="$db_pwd" ynh_app_setting_set --app="$app" --key="db_name" --value="$db_name" -ynh_mysql_setup_db --db_user="$db_user" --db_name="$db_name" +ynh_app_setting_set --app="$app" --key="db_user" --value="$db_user" + +ynh_psql_test_if_first_run +ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE diff --git a/scripts/remove b/scripts/remove index 29ed05f..6a47a30 100644 --- a/scripts/remove +++ b/scripts/remove @@ -18,11 +18,10 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$(ynh_app_setting_get --app=$app --key=db_user) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - #================================================= # STANDARD REMOVE #================================================= @@ -45,12 +44,12 @@ ynh_script_progression --message="Stopping and removing the systemd service..." ynh_remove_systemd_config #================================================= -# REMOVE THE MYSQL DATABASE +# REMOVE THE DATABASE #================================================= -ynh_script_progression --message="Removing the MySQL database..." --weight=2 +ynh_script_progression --message="Removing the database..." --weight=2 # Remove a database if it exists, along with the associated user -ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" #================================================= # REMOVE DEPENDENCIES @@ -94,7 +93,7 @@ ynh_remove_logrotate ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user -ynh_system_user_delete --username=$app +ynh_system_user_delete --username="$app" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 10c5513..6cbfb2a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -32,6 +32,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$(ynh_app_setting_get --app=$app --key=db_user) +db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -64,7 +65,7 @@ ynh_restore_file --origin_path="$final_path" ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username="$app" #================================================= # RESTORE USER RIGHTS @@ -89,13 +90,13 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version" #================================================= -# RESTORE THE MYSQL DATABASE +# RESTORE THE DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=6 +ynh_script_progression --message="Restoring the database..." --weight=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 +ynh_psql_test_if_first_run +ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" +ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= # RESTORE SYSTEMD diff --git a/scripts/upgrade b/scripts/upgrade index 440d42f..24617da 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,10 +22,6 @@ is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) -db_name=$(ynh_app_setting_get --app=$app --key=app) -db_user=$(ynh_app_setting_get --app=$app --key=app) -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) - #================================================= # CHECK VERSION #================================================= @@ -124,7 +120,7 @@ fi ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username="$app" #================================================= # SPECIFIC UPGRADE @@ -170,7 +166,7 @@ ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=2 #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server listening" +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="HTTP Server listening" #================================================= # RELOAD NGINX @@ -183,4 +179,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last \ No newline at end of file +ynh_script_progression --message="Upgrade of $app completed" --last