Support optional systemd service files collab/berick/ansible-installer-ubuntu-16.04
authorBill Erickson <berickxx@gmail.com>
Wed, 14 Jun 2017 16:34:03 +0000 (12:34 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 19 Jun 2017 17:48:12 +0000 (13:48 -0400)
Adds a new settings variable 'use_service_files', which defaults to
'false'.

Improve Apache's process handling by leaving Apache's shut down after
install and only restarting them after EG services are started.

Tweak readme to use shorter ansible invocations.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
README.adoc
evergreen/apache.yml
extras/main.yml
extras/service-files/evergreen-reporter.service.j2 [new file with mode: 0644]
extras/service-files/opensrf.service.j2 [new file with mode: 0644]
extras/services.yml [new file with mode: 0644]
extras/start.yml
opensrf/websockets.yml
settings.yml

index d60227c..339c3fb 100644 (file)
@@ -17,10 +17,10 @@ sudo ansible-playbook playbook.yml
 
 # Alternate example demonstrating variable overrides by installing a 
 # specific OpenSRF branch.
-# sudo ansible-playbook playbook.yml --extra-vars "osrf_git_branch=rel_2_5"
+# sudo ansible-playbook playbook.yml -e osrf_git_branch=rel_2_5
 
 # Install with the sample locales defined in translations.yml
-# sudo ansible-playbook playbook.yml --extra-vars "translations=true"
+# sudo ansible-playbook playbook.yml -e translations=true
 
 # Install with a different deployment user (named 'deploy') on a remote machine
 # sudo ansible-playbook playbook.yml -e hosts=other.example.org -e deploy_user=deploy
@@ -45,4 +45,5 @@ Entry point for each collection of sub-tasks.
 
 === extras
 
-Optional packages not strictly required for OpenSRF and Evergreen.
+Optional packages and configuration not strictly required for OpenSRF 
+and Evergreen.
index 338e146..5efa3c8 100644 (file)
@@ -1,7 +1,11 @@
 # Apache
-- name: Stop apache2
+- name: Stop Apache2
   become: true
   service: name=apache2 state=stopped
+- name: Stop Apache2 Websockets
+  become: true
+# TODO: Use ansible 2.2 service: use=systemd
+  shell: systemctl stop apache2-websockets
 - name: Setup eg.conf
   become: true
   copy:
     dest: /etc/apache2/apache2.conf
     regexp: 'KeepAliveTimeout .*' 
     replace: 'KeepAliveTimeout 1'
-- name: Restarting Apache
-  become: true
-  service: name=apache2 state=started
-- name: Restarting Websockets
-  become: true
-# service name=apache2ctl-websockets state=restarted FAILS
-# ansible 2.2 supports a use=systemd flag that would likley resolve
-# this, since this works: systemctl restart apache2-websockets
-  shell: apache2ctl-websockets restart
-
+# Leave Apache's stopped until Evergreen services are started.
index fbf6854..108b4a8 100644 (file)
@@ -4,6 +4,9 @@
 - name: Install Nginx
   include: nginx.yml
   when: use_nginx
+- name: Install Service Files
+  include: services.yml
+  when: use_service_files
 - name: Starting Services
   include: start.yml
   when: start_services
diff --git a/extras/service-files/evergreen-reporter.service.j2 b/extras/service-files/evergreen-reporter.service.j2
new file mode 100644 (file)
index 0000000..02b9c26
--- /dev/null
@@ -0,0 +1,18 @@
+[Unit]
+Description=Evergreen Reporter
+After=opensrf.service
+BindsTo=opensrf.service
+
+[Service]
+User=opensrf
+Group=opensrf
+Type=forking
+Environment=PATH=/openils/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+#ExecStartPre=/bin/sleep 2
+
+# TODO: -c template variable
+ExecStart=/openils/bin/clark-kent.pl --daemon
+ExecStopPost=/bin/rm /tmp/reporter-LOCK
+
+#[Install]
+#WantedBy=multi-user.target
diff --git a/extras/service-files/opensrf.service.j2 b/extras/service-files/opensrf.service.j2
new file mode 100644 (file)
index 0000000..ede746b
--- /dev/null
@@ -0,0 +1,29 @@
+# TODO: 'Before' and 'After' reflect a single-server setup.
+# Make these configurable for cases where certain services 
+# (e.g. memcache) are not run on the same machine.
+
+[Unit]
+Description=Open Service Request Framework
+After=ejabberd.service memcached.service
+Before=apache2.service apache2-websockets.service
+Requries=memcached.service
+BindsTo=ejabberd.service
+
+[Service]
+User=opensrf
+Group=opensrf
+Type=oneshot
+RemainAfterExit=yes
+Environment=PATH=/openils/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+Environment=LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
+#ExecStartPre=/bin/sleep 5
+ExecStart=/openils/bin/osrf_control -l --start-all
+#ExecStartPost=/bin/sleep 10
+#ExecStartPost=-/bin/systemctl restart apache2.service
+#ExecStartPost=-/bin/systemctl restart apache2-websockets.service
+ExecStop=/openils/bin/osrf_control -l --stop-all
+
+#[Install]
+#WantedBy=multi-user.target
+#Alias=opensrf.service
+
diff --git a/extras/services.yml b/extras/services.yml
new file mode 100644 (file)
index 0000000..e60af8a
--- /dev/null
@@ -0,0 +1,19 @@
+- name: Install OpenSRF Service File
+  become: true
+  template: 
+    src: extras/service-files/opensrf.service.j2
+    dest: /lib/systemd/system/opensrf.service 
+    owner: root
+    group: root
+    mode: 0644
+- name: Install Evergreen Reporter Service File
+  become: true
+  template: 
+    src: extras/service-files/evergreen-reporter.service.j2
+    dest: /lib/systemd/system/evergreen-reporter.service 
+    owner: root
+    group: root
+    mode: 0644
+- name: Reload Systemd Configs
+  become: true
+  shell: systemctl daemon-reload
index 9929658..74913b9 100644 (file)
@@ -4,6 +4,12 @@
   environment:
     PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
   shell: osrf_control --localhost --restart-all
+  when: not use_service_files
+- name: Starting Services (systemd)
+  become: true
+# NOTE: ansible 2.2 adds a service: use=systemd flag
+  shell: systemctl restart opensrf.service
+  when: use_service_files
 - name: Giving Services Time To Start...
   pause: seconds=10
 - name: Running Autogen
   environment:
     PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
   shell: autogen.sh
-- name: Reloading Apache 
+- name: Restarting Apache
+  become: true
+  service: name=apache2 state=restarted
+- name: Restarting Websockets
   become: true
-  service: name=apache2 state=reloaded
+# service name=apache2ctl-websockets state=restarted FAILS
+# ansible 2.2 supports a use=systemd flag that would likley resolve
+# this, since this works: systemctl restart apache2-websockets
+  shell: systemctl restart apache2-websockets
+
index 82e978f..1cbc4d4 100644 (file)
@@ -28,6 +28,9 @@
       remote_src: true
       src: "{{repo_base}}/OpenSRF/examples/apache_24/websockets/apache2.conf"
       dest: /etc/apache2-websockets/apache2.conf
+  - name: Reload Systemd Configs
+    become: true
+    shell: systemctl daemon-reload
   when: websocketsconf.stat.isdir is not defined
 # NOTE: restarting websockets here fails because the SSL cert is not yet in place
 
index bf16922..90e4010 100644 (file)
@@ -39,6 +39,11 @@ use_rsyslog: true
 # Install and configure NGINX proxy
 use_nginx: true
 
+# Install systemd service files and use them to stop/start services.
+# Disabled by default since EG documentation generally refers to
+# the osrf_control script instead.
+use_service_files: false
+
 # Start Evergreen services when the install is complete.
 start_services: true