1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/codimd_ynh.git synced 2024-09-03 18:16:32 +02:00

move to postesql

This commit is contained in:
ericgaspar 2020-05-23 09:14:00 +02:00
parent b32e082487
commit 28d6e0d5cd
No known key found for this signature in database
GPG key ID: 574F281483054D44
11 changed files with 35 additions and 34 deletions

View file

@ -4,5 +4,5 @@ module.exports = {
'config': path.resolve('config.json'), 'config': path.resolve('config.json'),
'migrations-path': path.resolve('lib', 'migrations'), 'migrations-path': path.resolve('lib', 'migrations'),
'models-path': path.resolve('lib', 'models'), '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__'
} }

View file

@ -27,8 +27,8 @@
"password": "__DB_PASS__", "password": "__DB_PASS__",
"database": "__DB_NAME__", "database": "__DB_NAME__",
"host": "localhost", "host": "localhost",
"port": "3306", "port": "5432",
"dialect": "mysql" "dialect": "postgres"
} }
} }
} }

View file

@ -1,7 +1,7 @@
[Unit] [Unit]
Description=__APP__: collaborative Markdown notes Description=__APP__: collaborative Markdown notes
After=network.target After=network.target
After=mysql.service After=postgresql.service
[Service] [Service]
Type=simple Type=simple

View file

@ -17,8 +17,7 @@
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [
"nginx", "nginx"
"mysql"
], ],
"arguments": { "arguments": {
"install": [{ "install": [{

View file

@ -5,7 +5,7 @@
#================================================= #=================================================
# dependencies used by the app # dependencies used by the app
pkg_dependencies="apt-transport-https" pkg_dependencies="postgresql apt-transport-https"
nodejs_version="10" nodejs_version="10"

View file

@ -50,11 +50,11 @@ ynh_backup --src_path="$final_path"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" 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_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 # SPECIFIC BACKUP

View file

@ -31,7 +31,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application # Add settings here as needed by your application
db_name=$(ynh_app_setting_get --app=$app --key=db_name) 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) 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_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 # MODIFY URL IN NGINX CONF
@ -112,7 +112,7 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 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 # RELOAD NGINX

View file

@ -39,7 +39,7 @@ final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Register (book) web path # 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 # FIND AND OPEN A PORT
@ -68,7 +68,7 @@ ynh_script_progression --message="Installing dependencies..." --weight=20
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
# Install Nodejs # 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 # 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" 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_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name 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_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 # DOWNLOAD, CHECK AND UNPACK SOURCE

View file

@ -18,11 +18,10 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port) 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_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$(ynh_app_setting_get --app=$app --key=db_user) db_user=$(ynh_app_setting_get --app=$app --key=db_user)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
@ -45,12 +44,12 @@ ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_remove_systemd_config 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 # 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 # REMOVE DEPENDENCIES
@ -94,7 +93,7 @@ ynh_remove_logrotate
ynh_script_progression --message="Removing the dedicated system user..." --weight=1 ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user # Delete a system user
ynh_system_user_delete --username=$app ynh_system_user_delete --username="$app"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -32,6 +32,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port) port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$(ynh_app_setting_get --app=$app --key=db_user) 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 # 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 ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create --username=$app ynh_system_user_create --username="$app"
#================================================= #=================================================
# RESTORE USER RIGHTS # 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" 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_psql_test_if_first_run
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_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_execute_file_as_root --file="./db.sql" --database="$db_name"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD

View file

@ -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) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port) 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 # CHECK VERSION
#================================================= #=================================================
@ -124,7 +120,7 @@ fi
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_system_user_create --username=$app ynh_system_user_create --username="$app"
#================================================= #=================================================
# SPECIFIC UPGRADE # 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_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 # RELOAD NGINX
@ -183,4 +179,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression --message="Upgrade of $app completed" --last