diff --git a/roles/codimd/handlers/main.yml b/roles/codimd/handlers/main.yml index 866f2a0..67c3a3c 100644 --- a/roles/codimd/handlers/main.yml +++ b/roles/codimd/handlers/main.yml @@ -7,3 +7,7 @@ become: yes become_user: codimd +# Reload systemd daemons when a service file changes +- name: Reload systemd daemons + command: systemctl daemon-reload + diff --git a/roles/codimd/tasks/main.yml b/roles/codimd/tasks/main.yml index 29c210d..d48e7e4 100644 --- a/roles/codimd/tasks/main.yml +++ b/roles/codimd/tasks/main.yml @@ -27,7 +27,7 @@ # Connection to database - name: Connect CodiMD to PostgreSQL db template: - src: sequelizerc + src: sequelizerc.j2 dest: /var/local/codimd/codimd/.sequelizerc owner: codimd group: codimd @@ -41,9 +41,29 @@ become: yes become_user: codimd -# Config CodiMD -# config.json template +# Configure +- name: Configure CodiMD + template: + src: config.json.j2 + dest: /var/local/codimd/codimd/config.json + owner: codimd + group: codimd + mode: 0600 -# Config SystemD service -# NODE_ENV="production" npm start +# Service file +- name: Install CodiMD systemd unit + template: + src: 'systemd/codimd.service.j2' + dest: '/etc/systemd/system/codimd.service' + owner: root + group: root + mode: 0644 + notify: Reload systemd daemons + +# Run +- name: Ensure that CodiMD is started + service: + name: codimd + state: started + enabled: true diff --git a/roles/codimd/templates/config.json.j2 b/roles/codimd/templates/config.json.j2 new file mode 100644 index 0000000..6190751 --- /dev/null +++ b/roles/codimd/templates/config.json.j2 @@ -0,0 +1,38 @@ +{ + "production": { + "domain": "codimd.auro.re", + "debug": false, + "port": 8080, + "useSSL": false, + "protocolUseSSL": true, + "useCDN": false, + "csp": { + "enable": true, + "directives": { + }, + "upgradeInsecureRequests": "auto", + "addDefaults": true + }, + "db": { + "username": "codimd", + "password": "{{ postgresql_codimd_passwd }}", + "database": "codimd", + "host": "{{ postgresql_services_url }}", + "port": "5432", + "dialect": "postgres" + }, + "email": false, + "ldap": { + "url": "{{ ldap_master_uri }}", + "bindDn": null, + "bindCredentials": null, + "searchBase": "change this", + "searchFilter": "change this", + "searchAttributes": ["change this"], + "usernameField": "change this e.g. cn", + "useridField": "change this e.g. uid" + }, + "allowFreeURL": true + } +} + diff --git a/roles/codimd/templates/sequelizerc b/roles/codimd/templates/sequelizerc.j2 similarity index 100% rename from roles/codimd/templates/sequelizerc rename to roles/codimd/templates/sequelizerc.j2 diff --git a/roles/codimd/templates/systemd/codimd.service.j2 b/roles/codimd/templates/systemd/codimd.service.j2 new file mode 100644 index 0000000..4fcf211 --- /dev/null +++ b/roles/codimd/templates/systemd/codimd.service.j2 @@ -0,0 +1,20 @@ +# /etc/systemd/system/codimd.service +# Deployed with Aurore Ansible ! + +[Unit] +Description=CodiMD +After=syslog.target network-online.target mysql.service postgresql.service +Conflicts=shutdown.target + +[Service] +Type=simple +User=codimd +Group=codimd +WorkingDirectory=/var/local/codimd/codimd +Environment="NODE_ENV=production" +ExecStart=/usr/bin/nodejs /var/local/codimd/codimd/app.js +Restart=always + +[Install] +WantedBy=multi-user.target +