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

View file

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

View file

@ -1,4 +1,8 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
app=ynhexample
# The parameter $1 is the backup directory location
@ -9,6 +13,10 @@ sudo mkdir -p $backup_dir
# Backup sources & data
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"
sudo cp -a /etc/yunohost/apps/$app/. $backup_dir/yunohost
domain=$(sudo yunohost app setting $app domain)

View file

@ -1,4 +1,8 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
app=ynhexample
# Retrieve arguments
@ -12,15 +16,23 @@ sudo yunohost app setting $app admin -v "$admin"
sudo yunohost app setting $app is_public -v "$is_public"
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
exit 1
fi
sudo yunohost app checkurl $domain$path -a $app \
|| (echo "Path not available: $domain$path" && exit 1)
# Copy source files
final_path=/var/www/$app
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
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
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 :
#
#sudo rm -f /etc/php5/fpm/pool.d/$app.conf

View file

@ -1,4 +1,8 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
app=ynhexample
# The parameter $1 is the uncompressed restore directory location
@ -7,6 +11,14 @@ backup_dir=$1/apps/$app
# Restore sources & data
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
sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app
domain=$(sudo yunohost app setting $app domain)

View file

@ -1,4 +1,8 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
app=ynhexample
# Retrieve arguments
@ -13,7 +17,11 @@ path=${path%/}
# Copy source files
final_path=/var/www/$app
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
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf