Commit e4f090d4 by Pablo Molina

Solved #381, instalación con vagrant/ansible:

- Modificada instalación para que use Vagrant y/o Ansible
- Establecido NodeJS 4.x como versión del servidor
- Movida toda la configuración a roles de ansible
- Preparados roles para que funcionen con CentOS (similar a amazon AWS)
parent d69dfc9d
Showing with 460 additions and 351 deletions
......@@ -33,6 +33,7 @@ sails/src/config/logs
sails/src/node_modules
sails/src/assets/app/bower_components
sails/src/.tmp
sails/.vagrant
sails/config/tmp.sql
android/Pictogram/.idea
.idea
......
# Servidor de Pictogram e instalación del cliente web
En este directorio se encuentra el servidor web ([src](./src)) y la aplicación
web ([src/assets/app](./src/assets/app)). Los distintos ficheros de configuración
utilizados para la inicialización y el testeo de la aplicación se encuentran
en el directorio [conf](./conf).
## Instalación del servidor y el cliente web
## Dependencias
> Las distintas configuraciones aplicadas a la instalación pueden leerse en los `roles`
> de [ansible][9] creados para ello:
>
> - [Instalación de NodeJS][4]
> - [Instalación de MYSQL][5]
> - [Importación de la base de datos][6]
> - [Dependencias del cliente web][7]
> - [Dependencias y ejecución del servidor][8]
- Ubuntu >= 14.04
- Nodejs >= 0.10.37
- Npm >= 3.8.5
- Bower >= 1.4.1
### Opción A (producción): ejecución en la máquina local
## Instalación del servidor y el cliente web
1. Ejecutar [./install.sh][3].
- Configurar el cliente ssh para poder conectarse a los servidores de
pre.yottacode.com (se intentará conectar como el usuario ec2-user).
- Ejecutar el script [install.sh](./install.sh) para instalar todas las
dependencias del servidor y el cliente web.
- Acceder al directorio [conf](./conf) para la instalación de la base de datos.
### Opción B (desarrollo): ejecución en una máquina virtual generada automáticamente
1. Instalar [virtualbox][1] y [vagrant][2].
2. Ejecutar `vagrant up` desde este directorio.
> **Importante**: el script utilizado creará un entorno para el servidor desde
> cero, por lo que **pueden perderse los datos** almacenados por usuarios.
## Desarrollo y pruebas
Para ejecutar el servidor como desarrollo se debe acceder al directorio
[conf](./conf) e instalar los datos de la base de datos necesarios.
## Ejecución
Para lanzar el servidor hay que acceder al directorio [src](./src) y ejecutar
uno de esos comandos:
Para lanzar el servidor hay que acceder al directorio [src][10] y ejecutar uno de esos comandos:
- `sails lift`: para un servidor corriente
- `sails console`: para un servidor con un intérprete de nodejs con las
variables de sails expuestas
- `sails console`: para un servidor con un intérprete de nodejs con las variables de sails
expuestas, de forma que puede manipularse durate su ejecución
> Si se añade el parámetro --prod, se ejecutará en modo producción
> El servidor se ejecutará en [localhost:1337/app](http://localhost:1337/app)
[1]: https://www.virtualbox.org/
[2]: https://www.vagrantup.com/
[3]: ./install.sh
[4]: ./roles/nodejs
[5]: ./roles/mysql
[6]: ./roles/database
[7]: ./roles/webapp
[8]: ./roles/server
[9]: https://www.ansible.com/
[10]: ./src
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# "ubuntu/trusty64" for ubuntu environment
# "puphpet/centos65-x64" for AWS similar environment
config.vm.box = "puphpet/centos65-x64"
config.vm.network "forwarded_port", guest: 1337, host: 1337
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provider "virtualbox" do |vb|
vb.memory = 1024
end
config.vm.provision "shell", path: "install.sh"
end
# Configuración de la base de datos
## Scripts
- [installdb.sh](./installdb.sh) elimina la base de datos existente y realiza
una instalación limpia para producción.
- [installdb-tests.sh](./installdb-test.sh) realiza el mismo proceso
que [installdb.sh](./installdb.sh) pero añadiendo los datos de tests.
- [installdb-autismojaen.sh](./installdb-autismojaen.sh) realiza el mismo
proceso que [installdb.sh](./installdb.sh), pero añadiendo los datos de
autismojaen.
> **Importante**: para no añadir la biblioteca de symbolstix de nuevo
> y conservarla en el caso de que ya esté en la base de datos se puede
> añadir la opción `--ignore-symbolstix` a todos los scripts (por ejemplo
> `installdb.sh --ignore-symbolstix` no importará estos datos).
## Orden de la importación
### Datos necesarios
- [init.sql](./pictodb-init.sql) inicializa el usuario y permisos de la base de
datos.
- _[init-ignoresymbolstix.sql](./sql/init-ignoresymbolstix.sql) realiza el mismo
proceso que [init.sql](./sql/init.sql), pero ignorando a symbolstix._
- [pictodb-schema.sql](./sql/pictodb-schema.sql) contiene el esquema de la base de
datos.
- _[symbolstix-categories.sql](./sql/symbolstix-categories.sql) añade las
categorías de symbolstix._
- _[symbolstix-metadata.sql](./sql/symbolstix-metadata.sql) añade los
metadatos de symbolstix._
- [pictodb-data.sql](./sql/pictodb-data.sql) contiene la información básica que
la aplicación necesita para funcionar.
- [triggers-enrolments-integrity-constraints.sql](./pictodb-triggers-enrolments-integrity-constraints.sql)
añade disparadores para el control de integridad de inscripciones.
- [triggers-sessions-integrity-constraints.sql](./pictodb-triggers-enrolments-integrity-constraints.sql)
añade disparadores para el control de integridad de sesiones.
### Añadido de datos de desarrollo y pruebas
- [test.sql](./sql/test-autismojaen.sql) contiene datos para el desarrollo y
pruebas de la aplicación.
- [test-autismojaen.sql](./sql/test-autismojaen.sql) añade los datos de
autismojaen.
## Notes
### Importación de datos
To import `pictodb-data.sql` into MySQL without foreign key constraints, ensure
that the imported file starts with `SET foreign_key_checks=0;` and then you turn
on it again with `SET foreign_key_checks=1;`
### Eliminando la base de datos completa
```sql
SET foreign_key_checks=0;
DROP TABLE `action`, `device`, `enrolment`, `instruction`, `license`,
`license_activation`, `meta_picto`, `meta_stu`, `method`, `office`,
`official_dev`, `picto`, `picto_acl`, `picto_core`, `picto_core_cat`,
`picto_exp`, `picto_tag`, `picto_tag_sup`, `source`, `student`, `stu_picto`,
`stu_sup`, `stu_sup_dev`, `supervisor`, `try`, `working_session`;
SET foreign_key_checks=1;
```
#!/bin/bash
ROOT_PASSWD=passwd
IGNORE_SYMBOLSTIX=false
USAGE="Usage: ${0##*/} <mysql root pwd> [--ignore-symbolstix]"
DBUSER=pictodbuser
DBNAME=pictodb
function do_exit {
echo $USAGE
exit 1
}
function execute_db {
echo $1
mysql -u $DBUSER -pp1KT015 $DBNAME < $1
}
function main {
if [ $# -eq 0 ]; then do_exit; fi
if [ $# -gt 2 ]; then do_exit; fi
if [ $# -eq 1 ]; then ROOT_PASSWD=$1; fi
if [ $# -eq 2 ]; then
if [ $2 != '--ignore-symbolstix' ]; then do_exit; fi
ROOT_PASSWD=$1
IGNORE_SYMBOLSTIX=true
fi
if [ $IGNORE_SYMBOLSTIX == true ]; then
echo Init ignoring symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init-ignoresymbolstix.sql
else
echo Init with symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init.sql
fi
execute_db ./sql/pictodb-schema.sql
execute_db ./sql/pictodb-data.sql
execute_db ./sql/test-autismojaen.sql
if [ $IGNORE_SYMBOLSTIX == false ]; then
execute_db ./sql/symbolstix-categories.sql
execute_db ./sql/symbolstix-metadata.sql
fi
execute_db ./sql/triggers-enrolments-integrity-constraints.sql
execute_db ./sql/triggers-sessions-integrity-constraints.sql
}
main "$@"
#!/bin/bash
ROOT_PASSWD=passwdd
IGNORE_SYMBOLSTIX=false
USAGE="Usage: ${0##*/} <mysql root pwd> [--ignore-symbolstix]"
DBUSER=pictodbuser
DBNAME=pictodb
function do_exit {
echo $USAGE
exit 1
}
function execute_db {
echo $1
mysql -u $DBUSER -pp1KT015 $DBNAME < $1
}
function main {
if [ $# -eq 0 ]; then do_exit; fi
if [ $# -gt 2 ]; then do_exit; fi
if [ $# -eq 1 ]; then ROOT_PASSWD=$1; fi
if [ $# -eq 2 ]; then
if [ $2 != '--ignore-symbolstix' ]; then do_exit; fi
ROOT_PASSWD=$1
IGNORE_SYMBOLSTIX=true
fi
if [ $IGNORE_SYMBOLSTIX == true ]; then
echo Init ignoring symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init-ignoresymbolstix.sql
else
echo Init with symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init.sql
fi
execute_db ./sql/pictodb-schema.sql
execute_db ./sql/pictodb-data.sql
execute_db ./sql/test.sql
if [ $IGNORE_SYMBOLSTIX == false ]; then
execute_db ./sql/symbolstix-categories.sql
execute_db ./sql/symbolstix-metadata.sql
fi
execute_db ./sql/triggers-enrolments-integrity-constraints.sql
execute_db ./sql/triggers-sessions-integrity-constraints.sql
}
main "$@"
#!/bin/bash
ROOT_PASSWD=passwd
IGNORE_SYMBOLSTIX=false
USAGE="Usage: ${0##*/} <mysql root pwd> [--ignore-symbolstix]"
DBUSER=pictodbuser
DBNAME=pictodb
function do_exit {
echo $USAGE
exit 1
}
function execute_db {
echo $1
mysql -u $DBUSER -pp1KT015 $DBNAME < $1
}
function main {
if [ $# -eq 0 ]; then do_exit; fi
if [ $# -gt 2 ]; then do_exit; fi
if [ $# -eq 1 ]; then ROOT_PASSWD=$1; fi
if [ $# -eq 2 ]; then
if [ $2 != '--ignore-symbolstix' ]; then do_exit; fi
ROOT_PASSWD=$1
IGNORE_SYMBOLSTIX=true
fi
if [ $IGNORE_SYMBOLSTIX == true ]; then
echo Init ignoring symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init-ignoresymbolstix.sql
else
echo Init with symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init.sql
fi
execute_db ./sql/pictodb-schema.sql
execute_db ./sql/pictodb-data.sql
if [ $IGNORE_SYMBOLSTIX == false ]; then
execute_db ./sql/symbolstix-categories.sql
execute_db ./sql/symbolstix-metadata.sql
fi
execute_db ./sql/triggers-enrolments-integrity-constraints.sql
execute_db ./sql/triggers-sessions-integrity-constraints.sql
}
main "$@"
/// template file for sails/src/assets/app/js/config.js
'use strict';
/* Configuration constants */
angular.module('dashboardConfig', [])
.constant('config', {
'backend': 'https://sinai-fernando.ujaen.es:9944'
// 'backend': 'http://localhost:1337',
// 'backend': 'https://dev.yottacode.com',
// // 'backend': 'https://test.yottacode.com',
// // 'backend_ws': 'ws://localhost:1337',
// 'version': 0.1
});
#!/bin/bash
# Nodejs install
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install -y nodejs
sudo npm install -g npm
# Sails install
sudo npm install -g sails
# Sails log file
mkdir -p ./src/logs
touch ./src/logs/my_log_file.log
# Sails upload folder
mkdir -p ./upload
# Server dependencies installation
pushd ./src
npm install
popd
# Copy sails.io.js
pushd /tmp
rm -rf sailstempapp
sails new sailstempapp
popd
mkdir -p ./src/assets/app/js/lib/
cp /tmp/sailstempapp/assets/js/dependencies/sails.io.js ./src/assets/app/js/lib/
rm -rf /tmp/sailstempapp
# Link configuration file
ln ./conf/js/config.js ./src/assets/app/js/config.js
ln ./conf/js/local.js ./src/assets/app/js/local.js
# Download project assets
scp ec2-user@pre.yottacode.com:~/symbolstx.zip .
scp ec2-user@pre.yottacode.com:~/upload.zip .
unzip symbolstx
unzip upload
rm symbolstx.zip
rm upload.zip
# Client dependencies installation
sudo npm install -g bower
pushd ./src/assets/app
bower install
popd
echo "-- Installing ansible"
if [ -e "/usr/bin/apt-get" ]; then
echo "-- Installing using apt-get"
sudo apt-get install -y software-properties-common
sudo apt-add-repository -y ppa:ansible/ansible
sudo apt-get update -y
sudo apt-get install -y ansible
elif [ -e "/usr/bin/yum" ]; then
echo "-- Installing using yum"
sudo yum -y install epel-release
sudo yum -y install ansible
else
echo "XX Cannot install ansible"
exit
fi
echo "XX TODO: Downloading project assets"
# scp ec2-user@pre.yottacode.com:~/symbolstx.zip .
# scp ec2-user@pre.yottacode.com:~/upload.zip .
# unzip symbolstx
# unzip upload
# rm symbolstx.zip
# rm upload.zip
echo "-- Running ansible playbook"
function runAnsiblePlaybook {
echo "-- Running playbook from $(pwd)"
ansible-playbook playbook.yml --extra-vars="server_path=$(pwd)"
}
if [ -e "playbook.yml" ]; then
runAnsiblePlaybook
elif [ -e "/vagrant/playbook.yml" ]; then
cd /vagrant && runAnsiblePlaybook
elif [ -e "/home/vagrant/sync/playbook.yml" ]; then
cd /home/vagrant/sync && runAnsiblePlaybook
else
echo "XX Playbook not found, provision not finished"
exit
fi
---
- hosts: localhost
become: yes
connection: local
roles:
- webapp
- server
# Rol de configuración de la base de datos para pictogram
Elimina toda la información escrita en la base de datos para generar una nueva con los esquemas
necesarios. En el caso de establecer la variable `database_ignore_symbolstix` a `True`, los datos
de las bases de datos de symbolstx quedarán intactos y no serán reimportados.
Los ficheros SQL que importará este rol son los siguientes:
- [init][1] inicializa el usuario y permisos de la base de datos.
- [init-ignoresymbolstix][2] realiza el mismo proceso que [init][1], pero manteniendo
los datos almacenados por symbolstx.
- [pictodb-schema][3] contiene el esquema de la base de datos.
- [pictodb-data][4] contiene la información básica que la aplicación necesita para funcionar.
- [symbolstx-categories][5] añade las categorías de symbolstx.
- [symbolstix-metadata][6] añade traducciones para symbolstx.
- [triggers-enrolments-integrity-constraints][7] añade disparadores para el control de
integridad de inscripciones.
- [triggers-sessions-integrity-constraints][8] añade disparadores para el control de integridad
de sesiones.
- [test-caja][9] contiene datos para el test de CAJA.
- [test-autismojaen][10] añade los datos para el test de autismojaen.
[1]: ./files/init.sql
[2]: ./files/init-ignoresymbolstix.sql
[3]: ./files/pictodb-schema.sql
[4]: ./files/pictodb-data.sql
[5]: ./files/symbolstx-categories.sql
[6]: ./files/symbolstx-metadata.sql
[7]: ./files/triggers-enrolments-integrity-constraints.sql
[8]: ./files/triggers-sessions-integrity-constraints.sql
[9]: ./files/test-autismojaen.sql
[10]: ./files/test-caja.sql
......@@ -2,15 +2,25 @@ GRANT USAGE ON *.* TO 'pictodbuser'@'localhost';
DROP USER 'pictodbuser'@'localhost';
CREATE USER 'pictodbuser'@'localhost' identified by 'p1KT015';
CREATE DATABASE symbolstixdb;
DROP DATABASE IF EXISTS symbolstixdb;
CREATE DATABASE IF NOT EXISTS symbolstixdb;
CREATE DATABASE IF NOT EXISTS pictodb;
CREATE TABLE IF NOT EXISTS pictodb.picto (c CHAR(1));
CREATE TABLE IF NOT EXISTS pictodb.pictocat (c CHAR(1));
CREATE TABLE IF NOT EXISTS pictodb.catexp (c CHAR(1));
CREATE TABLE IF NOT EXISTS pictodb.picto_exp (c CHAR(1));
alter table pictodb.picto rename symbolstixdb.picto;
alter table pictodb.pictocat rename symbolstixdb.pictocat;
alter table pictodb.catexp rename symbolstixdb.catexp;
alter table pictodb.picto_exp rename symbolstixdb.picto_exp;
SET foreign_key_checks=0;
DROP DATABASE pictodb;
DROP DATABASE IF EXISTS pictodb;
CREATE DATABASE IF NOT EXISTS pictodb;
SET foreign_key_checks=1;
CREATE DATABASE pictodb;
alter table symbolstixdb.picto rename pictodb.picto;
alter table symbolstixdb.pictocat rename pictodb.pictocat;
alter table symbolstixdb.catexp rename pictodb.catexp;
......@@ -18,5 +28,4 @@ alter table symbolstixdb.picto_exp rename pictodb.picto_exp;
grant all privileges on pictodb.* to pictodbuser;
flush privileges;
DROP DATABASE symbolstixdb;
DROP DATABASE IF EXISTS symbolstixdb;
......@@ -10,7 +10,6 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
......@@ -389,7 +388,7 @@ CREATE TABLE IF NOT EXISTS `stu_picto` (
`attributes` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'JSON object describing the properties of the picto according to the properties defined in meta_picto',
PRIMARY KEY (`id`),
KEY `fk_picto` (`id_pic`),
KEY `id_stu` (`id_stu`),
KEY `id_stu` (`id_stu`),
UNIQUE `uq_stupicto` (`id_stu`,`id_pic`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
......@@ -472,7 +471,7 @@ CREATE TABLE IF NOT EXISTS `try` (
--
-- Estructura de tabla para la tabla `working_session`
--
-- NOTA: current es un atributo derivado que es necesario porque MySQL 5.1
-- NOTA: current es un atributo derivado que es necesario porque MySQL 5.1
-- no soporta correctamente indices con valor unico donde un campo es NULL
-- Trabaja en combinación al índice unico (id_sup,current) (idx_ws_supcur)
--
......@@ -526,7 +525,7 @@ ALTER TABLE `meta_instruction`
--
ALTER TABLE `meta_method`
ADD CONSTRAINT `fk_met_sup` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`);
--
-- Filtros para la tabla `office`
......@@ -630,29 +629,29 @@ ALTER TABLE `working_session`
--
CREATE ALGORITHM=UNDEFINED
VIEW `v_stu_last_ws_time` AS
CREATE ALGORITHM=UNDEFINED
VIEW `v_stu_last_ws_time` AS
SELECT M.`id_stu`AS id_stu,
MAX(WS.begin) AS time
FROM
`working_session` AS WS join
`instruction` AS I join
`method` AS M
WHERE
`method` AS M
WHERE
WS.`id_ins` =I.`id`
and I.`id_met` = M.`id`
group by M.`id_stu`;
CREATE ALGORITHM=UNDEFINED
VIEW `v_stu_last_instruction` AS
select
WS.`id` AS `id_ws`,
CREATE ALGORITHM=UNDEFINED
VIEW `v_stu_last_instruction` AS
select
WS.`id` AS `id_ws`,
WS.`begin` AS `ws_begin`,
WS.`end` AS `ws_end`,
WS.`description` AS `ws_description`,
I.`name` AS `ins_name`,
M.`name` AS `met_name`,
M.`id_stu` AS `id_stu`
M.`id_stu` AS `id_stu`
FROM
`working_session` AS WS join
`instruction` AS I join
......@@ -682,7 +681,6 @@ VIEW `v_stu_last_instruction` AS
-- KEY `id_ins` (`id_ins`)
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
......@@ -11,16 +11,17 @@ FOR EACH ROW
BEGIN
DECLARE max_enr,curr_enr INT;
IF new.id_off IS NOT NULL THEN
SELECT
SELECT
max_students, current_students INTO max_enr, curr_enr
FROM
FROM
office
WHERE
WHERE
office.id=new.id_off;
IF curr_enr>=max_enr THEN
SIGNAL SQLSTATE '20001'
SET MESSAGE_TEXT = 'Max number of enrolments reached';
-- Needed hack for mysql 5.1
-- http://stackoverflow.com/questions/10617136/why-is-signal-keyword-not-working-in-mysql-5-1-48
CALL raise_error_max_number_of_enrolments_reached;
END IF;
END IF;
END;;
......@@ -31,41 +32,41 @@ AFTER INSERT ON student
FOR EACH ROW
BEGIN
UPDATE
office
SET
UPDATE
office
SET
current_students=current_students+1
WHERE
WHERE
office.id=new.id_off;
END;;
-- Integrity rule 3: office.current_enrolments and supervisor assigments updating.
-- Integrity rule 3: office.current_enrolments and supervisor assigments updating.
CREATE TRIGGER TRG_MODIFY_STUDENT_ENROLMENTS
AFTER UPDATE ON student
FOR EACH ROW
BEGIN
IF NOT (old.id_off<=>new.id_off) THEN
IF (old.id_off IS NOT NULL) THEN
UPDATE
UPDATE
office
SET
current_students=current_students-1
WHERE
office.id=old.id_off;
current_students=current_students-1
WHERE
office.id=old.id_off;
DELETE
stu_sup
FROM
stu_sup
FROM
stu_sup INNER JOIN supervisor ON (stu_sup.id_sup=supervisor.id)
WHERE
id_stu=new.id AND old.id_off=supervisor.id_off;
id_stu=new.id AND old.id_off=supervisor.id_off;
END IF;
IF (new.id_off IS NOT NULL) THEN
UPDATE
UPDATE
office
SET
current_students=current_students+1
WHERE
office.id=new.id_off;
current_students=current_students+1
WHERE
office.id=new.id_off;
END IF;
END IF;
END;;
......@@ -74,14 +75,14 @@ END;;
CREATE TRIGGER TRG_DELETE_STUDENT_ENROLMENTS
AFTER DELETE ON student
FOR EACH ROW
BEGIN
IF old.id_off IS NULL THEN
UPDATE
BEGIN
IF old.id_off IS NULL THEN
UPDATE
office
SET
current_students=current_students-1
WHERE
office.id=old.id_off;
current_students=current_students-1
WHERE
office.id=old.id_off;
END IF;
END;;
DELIMITER ;
\ No newline at end of file
DELIMITER ;
---
dependencies:
- { role: mysql }
---
- name: Creates the database
mysql_db:
login_user: root
login_password: "{{ database_root_passwd }}"
name: all
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/init.sql"
when: database_ignore_symbolstix == False
- name: Creates the database without removing symbolstx
mysql_db:
login_user: root
login_password: "{{ database_root_passwd }}"
name: all
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/init-ignoresymbolstix.sql"
when: database_ignore_symbolstix == True
- name: Imports the schema and basic data
mysql_db:
login_user: "{{ database_user }}"
login_password: "{{ database_user_passwd }}"
name: "{{ database_name }}"
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/{{ item }}.sql"
with_items:
- pictodb-schema
- pictodb-data
- name: Imports selected tests
mysql_db:
login_user: "{{ database_user }}"
login_password: "{{ database_user_passwd }}"
name: "{{ database_name }}"
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/test-{{ item }}.sql"
with_items: "{{ database_tests }}"
- name: Imports symbolstx categories and metadata
mysql_db:
login_user: "{{ database_user }}"
login_password: "{{ database_user_passwd }}"
name: "{{ database_name }}"
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/symbolstx-{{ item }}.sql"
with_items:
- categories
- metadata
when: database_ignore_symbolstix == False
- name: Creates triggers
mysql_db:
login_user: "{{ database_user }}"
login_password: "{{ database_user_passwd }}"
name: "{{ database_name }}"
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/triggers-{{ item }}.sql"
with_items:
- enrolments-integrity-constraints
- sessions-integrity-constraints
---
database_files_relative_path: 'roles/database/files'
database_root_passwd: root
database_name: pictodb
database_user: pictodbuser
database_user_passwd: p1KT015
database_ignore_symbolstix: False
database_tests: [caja, autismojaen] # can be empty
# Rol de configuración de MYSQL
Este rol instala y arranca MYSQL, configurando una contraseña por defecto para el usuario root
---
- name: Set mysql root password
debconf:
name: mysql-server
question: "mysql-server/{{ item }}"
value: "{{ mysql_root_passwd | quote }}"
vtype: password
with_items:
- root_password
- root_password_again
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Update apt-get cache
apt:
update-cache: yes
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Install mysql packages
apt:
name: "{{ item }}"
state: present
with_items:
- mysql-server
- mysql-client
- python-mysqldb # required by ansible
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Install mysql packages
yum:
name: "{{ item }}"
state: present
with_items:
- mysql-server
- MySQL-python # required by ansible
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- name: Enable and start mysql service
service:
name: mysql
state: restarted
enabled: yes
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Enable and start mysql service
service:
name: mysqld
state: restarted
enabled: yes
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- name: Set mysql root password
shell: "/usr/bin/mysqladmin -u root -p{{ mysql_root_passwd | quote }} password {{ mysql_root_passwd | quote }}"
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
---
mysql_root_passwd: root
# Rol de instalación de NodeJS
Instala NodeJS (versión 4 o 5) como dependencia global
---
- name: Install HTTPS transport
apt:
name: apt-transport-https
state: installed
update_cache: yes
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Import the NodeSource key
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Add NodeSource repositories
apt_repository:
repo: "{{ item }} https://deb.nodesource.com/node_{{ nodejs_major_version }}.x {{ ansible_distribution_release }} main"
state: present
with_items:
- deb
- deb-src
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Add Nodesource repositories
yum:
name: "https://rpm.nodesource.com/pub_{{ nodejs_major_version }}.x/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm"
state: present
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- name: Update apt-get cache
apt:
update_cache: yes
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Install NodeJS
apt:
name: nodejs
state: present
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Install NodeJS
yum:
name: nodejs
state: present
enablerepo: 'epel,nodesource'
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
---
nodejs_major_version: 4 # or 5
# Rol de configuración del servidor de pictogram
Instala las dependencias necesarias para el servidor y lo ejecuta utilizando forever.js
//// template file for sails/src/config/local.js
// template file for sails/src/config/local.js
/**
* Local environment settings
......
This diff could not be displayed because it is too large.
---
dependencies:
- { role: nodejs }
- { role: database }
---
- name: Install NPM dependencies
npm:
path: "{{ server_path }}/{{ server_relative_path }}"
- name: Create log directory
file:
path: "{{ server_path }}/logs"
state: directory
- name: Create log file
file:
path: "{{ server_path }}/{{ server_relative_path }}/logs/my_log_file.log"
state: touch
- name: Install sails globaly
npm:
name: sails
global: yes
state: present
version: 0.12.3
- name: Copy sails.io.js file
copy:
src: sails.io.js
dest: "{{ server_path }}/{{ server_relative_webapp_path }}/js/lib/sails.io.js"
- name: Copy local.js configuration file
copy:
src: local.js
dest: "{{ server_path }}/{{ server_relative_webapp_path }}/js/local.js"
- name: Copy config.js template
template:
src: config.js.j2
dest: "{{ server_path }}/{{ server_relative_webapp_path }}/js/config.js"
- name: Install forever
npm:
name: forever
state: present
global: yes
- name: Launch sails server
shell: forever start app.js
args:
chdir: "{{ server_path }}/{{ server_relative_path }}"
'use strict';
/* Configuration constants */
angular.module('dashboardConfig', []).constant('config', {
backend: "{{ server_backend_url }}"
});
---
server_relative_path: 'src'
server_relative_webapp_path: 'src/assets/app'
# http://localhost:1337
# https://sinai-fernando.ujaen.es:9444
# https://dev.yottacode.com
# https://test.yottacode.com
server_backend_url: 'http://localhost:1337'
# Rol de configuración del cliente web de pictogram
Instala todas las dependencias necesarias para que la aplicación web funcione
---
dependencies:
- { role: nodejs }
---
- name: Install git
package:
name: git
state: present
- name: Install bower
npm:
name: bower
state: present
global: yes
- name: Install bower dependencies
bower: path="{{ webapp_path }}"
---
webapp_path: '/vagrant/src/assets/app'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment