Browse Source

Implement some best practice and mysql example

mbugeia 8 years ago
parent
commit
5bccfd3267
7 changed files with 68 additions and 13 deletions
  1. 8 2
      conf/nginx.conf
  2. 10 5
      manifest.json
  3. 8 0
      scripts/backup
  4. 17 5
      scripts/install
  5. 4 0
      scripts/remove
  6. 12 0
      scripts/restore
  7. 9 1
      scripts/upgrade

+ 8 - 2
conf/nginx.conf

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

+ 10 - 5
manifest.json

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

+ 8 - 0
scripts/backup

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

+ 17 - 5
scripts/install

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

+ 4 - 0
scripts/remove

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

+ 12 - 0
scripts/restore

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

+ 9 - 1
scripts/upgrade

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