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

@@ -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