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

Working Dont-code services

This commit is contained in:
Gérard Collin 2023-01-03 14:51:52 +01:00
parent d357d35c1b
commit dc97f2ff7c
9 changed files with 219 additions and 18 deletions

View file

@ -20,7 +20,7 @@
upgrade=0 from_commit=CommitHash
backup_restore=1
multi_instance=0
port_already_use=1 (8084)
port_already_use=1 (8083)
change_url=1
;;; Options
Email=ger@shared.collin.best

166
conf/index.html Normal file
View file

@ -0,0 +1,166 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dont-code services</title>
<style>
h1, h2, h3, h4, h5, h6 {
margin-bottom: 0.5rem;
font-weight: 400;
line-height: 1.5;
}
h1 {
font-size: 2.5rem;
}
h2 {
font-size: 2rem
}
h3 {
font-size: 1.75rem
}
h4 {
font-size: 1.5rem
}
h5 {
font-size: 1.25rem
}
h6 {
font-size: 1rem
}
.lead {
font-weight: 300;
font-size: 2rem;
}
.banner {
font-size: 2.7rem;
margin: 0;
padding: 2rem 1rem;
background-color: #00A1E2;
color: white;
}
body {
margin: 0;
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}
code {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 87.5%;
color: #e83e8c;
word-break: break-word;
}
.api-ok {
color: green;
}
.api-nok {
color: red;
}
.left-column {
padding: .75rem;
max-width: 75%;
min-width: 55%;
}
.right-column {
padding: .75rem;
max-width: 25%;
}
.container {
width: 100%;
padding-left: 1rem;
}
li {
margin: 0.75rem;
}
.right-section {
margin-left: 1rem;
padding-left: 0.5rem;
}
.right-section h3 {
padding-top: 0;
font-weight: 200;
}
.right-section ul {
border-left: 0.3rem solid #00A1E2;
list-style-type: none;
padding-left: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
/**
* Check if a relative ui is responding 200 or any other error
* @param uri
*/
function checkUri (uri, elementId) {
const req = new XMLHttpRequest();
req.addEventListener("load",ev => {
const elt=document.getElementById(elementId);
if ((ev.target.status<200) || (ev.target.status >= 300)) {
elt.innerText="Error "+ev.target.status;
elt.classList='api-nok';
}else {
elt.innerText="OK";
elt.classList='api-ok';
}
});
req.addEventListener("error",ev => {
const elt=document.getElementById(elementId);
elt.innerText="Failed";
elt.classList='api-nok';
});
req.open("GET", uri);
req.send();
}
window.onload = function() {
checkUri('preview/sessions', 'Preview');
// checkUri('ide/', 'Builder');
checkUri('project', 'Project');
checkUri('data/test', 'Data');
};
</script>
<div class="banner lead">
Dont-code services status page
</div>
<div class="container">
<p class="lead">Congratulations, your Dont-code services have been installed.</p>
<div>
<h2>Status of each service:</h2>
<ul>
<li>Preview service : <span id="Preview">Checking...</span></li>
<li>Builder service : <span id="Builder">Cannot be checked for now.</span></li>
<li>Project service : <span id="Project">Checking...</span></li>
<li>Data service : <span id="Data">Checking...</span></li>
</ul>
</div>
</div>
</body>
</html>

View file

@ -1,6 +1,12 @@
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
# Path to source
alias __HTML_PATH__/;
index index.html;
location __PATH__/ide {
proxy_pass http://localhost:__PORT_IDE__/ide;
proxy_http_version 1.1;

View file

@ -31,6 +31,7 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
#=================================================
@ -50,10 +51,10 @@ ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE DOCUMENT DIR
# BACKUP THE HTML AND DOCUMENT DIR
#=================================================
ynh_backup --src_path="$document_path" --is_big
ynh_backup --src_path="$html_path" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION

View file

@ -35,6 +35,7 @@ port_ide=$(ynh_app_setting_get --app=$app --key=port_ide)
port_preview=$(ynh_app_setting_get --app=$app --key=port_preview)
port_project=$(ynh_app_setting_get --app=$app --key=port_project)
port_data=$(ynh_app_setting_get --app=$app --key=port_data)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
#=================================================

View file

@ -57,7 +57,9 @@ ynh_script_progression --message="Validating installation parameters..." --weigh
### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
final_path=/opt/yunohost/$app
html_path=/usr/share/nginx/html/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
test ! -e "$html_path" || ynh_die --message="This path already contains a html folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
@ -203,15 +205,19 @@ ynh_add_nginx_config
#=================================================
# Create document storage
#=================================================
document_path=/usr/share/nginx/html/$app/docs
document_path=$html_path/docs
test ! -e "$document_path" || ynh_die --message="This path already contains a folder"
mkdir --parents $document_path
ynh_app_setting_set --app=$app --key=html_path --value=$html_path
ynh_app_setting_set --app=$app --key=document_path --value=$document_path
chmod 750 "$document_path"
chmod -R o-rwx "$document_path"
chown -R $app:www-data "$document_path"
# Add the status page
ynh_add_config --template="index.html" --destination="$html_path/index.html"
chmod 750 "$html_path"
chmod -R o-rwx "$html_path"
chown -R $app:www-data "$html_path"
document_url=https://${domain}${path_url}/docs

View file

@ -25,6 +25,7 @@ port_project=$(ynh_app_setting_get --app=$app --key=port_project)
port_data=$(ynh_app_setting_get --app=$app --key=port_data)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
PORT_LIST=($port_ide $port_preview $port_project $port_data)
@ -67,7 +68,7 @@ ynh_remove_logrotate
#=================================================
# REMOVE THE MONGO DATABASE
#=================================================
ynh_script_progression --message="Removing the Mongo database..." --weight=1
ynh_script_progression --message="Removing the Mongo databases..." --weight=1
# Remove a database if it exists, along with the associated user
for db_name in "${MONGO_DB_LIST[@]}"
@ -88,10 +89,10 @@ ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DOCUMENT DIR
#=================================================
ynh_script_progression --message="Removing document directory..." --weight=1
ynh_script_progression --message="Removing html directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$document_path"
ynh_secure_remove --file="$html_path"
#=================================================
# REMOVE NGINX CONFIGURATION

View file

@ -34,6 +34,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
public_key=$(ynh_app_setting_get --app=$app --key=public_key)
@ -83,9 +84,9 @@ fi
#=================================================
# RESTORE THE DOCUMENTS DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the document directory..." --weight=1
ynh_script_progression --message="Restoring the html directory..." --weight=1
ynh_restore_file --origin_path="$document_path" --not_mandatory
ynh_restore_file --origin_path="$html_path" --not_mandatory
mkdir -p $document_path
@ -95,9 +96,9 @@ mkdir -p $document_path
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$document_path"
chmod -R o-rwx "$document_path"
chown -R $app:www-data "$document_path"
chmod 750 "$html_path"
chmod -R o-rwx "$html_path"
chown -R $app:www-data "$html_path"
#=================================================
# SPECIFIC RESTORATION
@ -125,7 +126,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE MONGO DATABASES
#=================================================
ynh_script_progression --message="Restoring the Mongo database..." --weight=1
ynh_script_progression --message="Restoring the Mongo databases..." --weight=1
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
ynh_mongo_setup_db --db_user=$db_user --db_name=${MONGO_DB_LIST[0]} --db_pwd=$db_pwd

View file

@ -27,6 +27,7 @@ port_data=$(ynh_app_setting_get --app=$app --key=port_data)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
PORT_LIST=($port_ide $port_preview $port_project $port_data)
@ -71,8 +72,18 @@ done
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# Nothing to do for now
# Create html_path if needed
if [ -z "$html_path" ]; then
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
html_path=/usr/share/nginx/html/$app
ynh_app_setting_set --app=$app --key=html_path --value=$html_path
mkdir --parents $html_path
chmod 750 "$html_path"
chmod -R o-rwx "$html_path"
chown -R $app:www-data "$html_path"
fi
#=================================================
# CREATE DEDICATED USER
@ -124,6 +135,14 @@ ynh_install_mongo --mongo_version=$mongo_version
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
# Do we need to upgrade the status index ? Do it now as html_path variable is needed for nginx file
# Always Upgrade the status page
ynh_add_config --template="index.html" --destination="$html_path/index.html"
chmod 750 "$html_path/index.html"
chmod o-rwx "$html_path/index.html"
chown $app:www-data "$html_path/index.html"
# Create a dedicated NGINX config
ynh_add_nginx_config