1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/laverna_ynh.git synced 2024-09-03 19:36:06 +02:00

Implement some best practice and mysql example

This commit is contained in:
mbugeia 2015-10-27 16:03:21 +01:00
parent 3b0b1bb962
commit 5bccfd3267
7 changed files with 68 additions and 13 deletions

View file

@ -3,6 +3,11 @@ location YNH_WWW_PATH {
# Path to source # Path to source
alias YNH_WWW_ALIAS ; alias YNH_WWW_ALIAS ;
# rewrite all http request to https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
# Example PHP configuration # Example PHP configuration
index index.php; index index.php;
@ -22,8 +27,9 @@ location YNH_WWW_PATH {
fastcgi_index index.php; fastcgi_index index.php;
include fastcgi_params; include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user; fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
} }
# Include SSOWAT user panel. # Include SSOWAT user panel.

View file

@ -2,7 +2,8 @@
"name": "YunoHost example app", "name": "YunoHost example app",
"id": "ynhexample", "id": "ynhexample",
"description": { "description": {
"en": "Example package for Yunohost applications." "en": "Example package for Yunohost applications.",
"fr": "Exemple de package d'application pour Yunohost."
}, },
"licence": "free", "licence": "free",
"maintainer": { "maintainer": {
@ -16,14 +17,16 @@
{ {
"name": "domain", "name": "domain",
"ask": { "ask": {
"en": "Choose a domain for ynhexample" "en": "Choose a domain for ynhexample",
"fr": "Choisissez un domaine pour ynhexample"
}, },
"example": "example.com" "example": "example.com"
}, },
{ {
"name": "path", "name": "path",
"ask": { "ask": {
"en": "Choose a path for ynhexample" "en": "Choose a path for ynhexample",
"fr": "Choisissez un chemin pour ynhexample"
}, },
"example": "/example", "example": "/example",
"default": "/example" "default": "/example"
@ -31,14 +34,16 @@
{ {
"name": "admin", "name": "admin",
"ask": { "ask": {
"en": "Choose an admin user" "en": "Choose an admin user",
"fr": "Choisissez l'administrateur"
}, },
"example": "johndoe" "example": "johndoe"
}, },
{ {
"name": "is_public", "name": "is_public",
"ask": { "ask": {
"en": "Is it a public application ?" "en": "Is it a public application ?",
"fr": "Est-ce une application publique ?"
}, },
"choices": ["Yes", "No"], "choices": ["Yes", "No"],
"default": "Yes" "default": "Yes"

View file

@ -1,4 +1,8 @@
#!/bin/bash #!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
app=ynhexample app=ynhexample
# The parameter $1 is the backup directory location # The parameter $1 is the backup directory location
@ -9,6 +13,10 @@ sudo mkdir -p $backup_dir
# Backup sources & data # Backup sources & data
sudo cp -a /var/www/$app/. $backup_dir/sources sudo cp -a /var/www/$app/. $backup_dir/sources
# Backup mysql database if needed
# db_pwd=$(sudo yunohost app setting $app mysqlpwd)
# sudo mysqldump -u $app -p$db_pwd $app > $backup_dir/$app.dmp
# Copy Nginx and YunoHost parameters to make the script "standalone" # Copy Nginx and YunoHost parameters to make the script "standalone"
sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost
domain=$(sudo yunohost app setting $app domain) domain=$(sudo yunohost app setting $app domain)

View file

@ -1,4 +1,8 @@
#!/bin/bash #!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
app=ynhexample app=ynhexample
# Retrieve arguments # Retrieve arguments
@ -12,15 +16,23 @@ sudo yunohost app setting $app admin -v "$admin"
sudo yunohost app setting $app is_public -v "$is_public" sudo yunohost app setting $app is_public -v "$is_public"
# Check domain/path availability # Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app sudo yunohost app checkurl $domain$path -a $app \
if [[ ! $? -eq 0 ]]; then || (echo "Path not available: $domain$path" && exit 1)
exit 1
fi
# Copy source files # Copy source files
final_path=/var/www/$app final_path=/var/www/$app
sudo mkdir -p $final_path sudo mkdir -p $final_path
sudo cp -a ../sources/* $final_path sudo cp -a ../sources/. $final_path
# Set permissions to app files
# you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R root:root $final_path
# If your app use a MySQL database you can use these lines to bootstrap
# a database, an associated user and save the password in app settings
# db_pwd=$(openssl rand -hex 15)
# sudo yunohost app initdb $app -p $db_pwd
# sudo yunohost app setting $app mysqlpwd -v $db_pwd
# Modify Nginx configuration file and copy it to Nginx conf directory # Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf

View file

@ -13,6 +13,10 @@ sudo rm -rf /var/www/$app
# Remove configuration files # Remove configuration files
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
# If a database is used, remove it
# root_pwd=$(sudo cat /etc/yunohost/mysql)
# mysql -u root -p$root_pwd -e "DROP DATABASE $app ; DROP USER $app@localhost ;"
# If a dedicated php-fpm process is used : # If a dedicated php-fpm process is used :
# #
#sudo rm -f /etc/php5/fpm/pool.d/$app.conf #sudo rm -f /etc/php5/fpm/pool.d/$app.conf

View file

@ -1,4 +1,8 @@
#!/bin/bash #!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
app=ynhexample app=ynhexample
# The parameter $1 is the uncompressed restore directory location # The parameter $1 is the uncompressed restore directory location
@ -7,6 +11,14 @@ backup_dir=$1/apps/$app
# Restore sources & data # Restore sources & data
sudo cp -a $backup_dir/sources/. /var/www/$app sudo cp -a $backup_dir/sources/. /var/www/$app
# Restore permissions to app files
# you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R root:root $final_path
# Restore mysql database if needed
# db_pwd=$(sudo yunohost app setting $app mysqlpwd)
# sudo mysql -u $app -p$db_pwd $app < $backup_dir/$app.dmp
# Restore Nginx and YunoHost parameters # Restore Nginx and YunoHost parameters
sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app
domain=$(sudo yunohost app setting $app domain) domain=$(sudo yunohost app setting $app domain)

View file

@ -1,4 +1,8 @@
#!/bin/bash #!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
app=ynhexample app=ynhexample
# Retrieve arguments # Retrieve arguments
@ -13,7 +17,11 @@ path=${path%/}
# Copy source files # Copy source files
final_path=/var/www/$app final_path=/var/www/$app
sudo mkdir -p $final_path sudo mkdir -p $final_path
sudo cp -a ../sources/* $final_path sudo cp -a ../sources/. $final_path
# Set permissions to app files
# you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R root:root $final_path
# Modify Nginx configuration file and copy it to Nginx conf directory # Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf