From b8cfeef09a2b4b30330aad4a336f240aa35ce7a4 Mon Sep 17 00:00:00 2001
From: Andrea Dell'Amico <adellam@isti.cnr.it>
Date: Tue, 13 Feb 2018 20:14:03 +0100
Subject: [PATCH] stanford-corenlp: Add a playbook that installs the startup
 script. Add that role to the core-nlp playbook.

---
 stanford-corenlp/defaults/main.yml            | 23 +++++++++++++++++++
 stanford-corenlp/tasks/main.yml               | 18 +++++++++++++++
 .../templates/stanford-corenlp.upstart.j2     | 12 ++++++++++
 stanford-corenlp/templates/tint.upstart.j2    | 12 ++++++++++
 4 files changed, 65 insertions(+)
 create mode 100644 stanford-corenlp/defaults/main.yml
 create mode 100644 stanford-corenlp/tasks/main.yml
 create mode 100644 stanford-corenlp/templates/stanford-corenlp.upstart.j2
 create mode 100644 stanford-corenlp/templates/tint.upstart.j2

diff --git a/stanford-corenlp/defaults/main.yml b/stanford-corenlp/defaults/main.yml
new file mode 100644
index 0000000..14d6ef4
--- /dev/null
+++ b/stanford-corenlp/defaults/main.yml
@@ -0,0 +1,23 @@
+---
+# https://stanfordnlp.github.io/CoreNLP/
+stanford_corenlp_version: latest
+stanford_corenlp_name: stanford-corenlp
+stanford_corenlp_extension: war
+stanford_corenlp_file: '{{ stanford_corenlp_name }}-{{ stanford_corenlp_version }}.{{ stanford_corenlp_extension }}'
+stanford_corenlp_group_id: edu.stanford.nlp
+stanford_corenlp_languages:
+  - arabic
+  - chinese
+  - english
+  - english_kbp
+  - french
+  - german
+  - spanish
+
+stanford_corenlp_user: corenlp
+stanford_corenlp_base_dir: /opt/corenlp
+stanford_corenlp_dist_dir: '{{ stanford_corenlp_base_dir }}/stanford-corenlp'
+stanford_corenlp_log_dir: '{{ stanford_corenlp_base_dir }}/logs'
+stanford_corenlp_cmd: 'java -cp "*" -mx4g edu.stanford.nlp.pipeline.StanfordCoreNLPServer -props StanfordCoreNLP-english.properties -port 9000 -timeout 60000'
+
+tint_service_cmd: './tint-server.sh -p 9001'
diff --git a/stanford-corenlp/tasks/main.yml b/stanford-corenlp/tasks/main.yml
new file mode 100644
index 0000000..08b592b
--- /dev/null
+++ b/stanford-corenlp/tasks/main.yml
@@ -0,0 +1,18 @@
+---
+- block:
+    - name: Create the CoreNLP logs directory
+      file: dest={{ stanford_corenlp_log_dir }} state=directory owner={{ stanford_corenlp_user }}
+
+    - name: Install the CoreNLP startup script
+      template: src=stanford-corenlp.upstart.j2 dest=/etc/init/stanford-corenlp.conf owner=root group=root mode=0644
+
+    - name: Ensure that CoreNLP is enabled and running
+      service: name=stanford-corenlp state=started enabled=yes
+
+    - name: Install the tint service startup script
+      template: src=tint.upstart.j2 dest=/etc/init/tint.conf owner=root group=root mode=0644
+
+    - name: Ensure that the tint service is enabled and running
+      service: name=tint state=started enabled=yes
+
+  tags: [ 'corenlp', 'stanford_corenlp' ]
diff --git a/stanford-corenlp/templates/stanford-corenlp.upstart.j2 b/stanford-corenlp/templates/stanford-corenlp.upstart.j2
new file mode 100644
index 0000000..f2f34aa
--- /dev/null
+++ b/stanford-corenlp/templates/stanford-corenlp.upstart.j2
@@ -0,0 +1,12 @@
+description "Stanford CoreNLP"
+start on (local-filesystems and net-device-up IFACE!=lo)
+stop on runlevel [016]
+
+respawn
+respawn limit 10 5
+setuid {{ stanford_corenlp_user }}
+setgid {{ stanford_corenlp_user }}
+
+script
+  exec cd {{ stanford_corenlp_dist_dir }} {{ stanford_corenlp_cmd }}  > {{ stanford_corenlp_log_dir }}/corenlp.log 2>&1
+end script
diff --git a/stanford-corenlp/templates/tint.upstart.j2 b/stanford-corenlp/templates/tint.upstart.j2
new file mode 100644
index 0000000..4879825
--- /dev/null
+++ b/stanford-corenlp/templates/tint.upstart.j2
@@ -0,0 +1,12 @@
+description "TINT service"
+start on (local-filesystems and net-device-up IFACE!=lo)
+stop on runlevel [016]
+
+respawn
+respawn limit 10 5
+setuid {{ stanford_corenlp_user }}
+setgid {{ stanford_corenlp_user }}
+
+script
+  exec cd {{ stanford_corenlp_dist_dir }}/tint {{ tint_service_cmd }}  > {{ stanford_corenlp_log_dir }}/tint.log 2>&1
+end script