From 224fb8d04c0f172169f9774b999ba8f5a451525c Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 14 Jun 2017 12:34:03 -0400 Subject: [PATCH] Support optional systemd service files 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 --- README.adoc | 7 +++--- evergreen/apache.yml | 17 +++++-------- extras/main.yml | 3 +++ extras/service-files/evergreen-reporter.service.j2 | 18 ++++++++++++++ extras/service-files/opensrf.service.j2 | 29 ++++++++++++++++++++++ extras/services.yml | 19 ++++++++++++++ extras/start.yml | 17 +++++++++++-- opensrf/websockets.yml | 3 +++ settings.yml | 5 ++++ 9 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 extras/service-files/evergreen-reporter.service.j2 create mode 100644 extras/service-files/opensrf.service.j2 create mode 100644 extras/services.yml diff --git a/README.adoc b/README.adoc index d60227c93..339c3fb7c 100644 --- a/README.adoc +++ b/README.adoc @@ -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. diff --git a/evergreen/apache.yml b/evergreen/apache.yml index 338e14621..5efa3c890 100644 --- a/evergreen/apache.yml +++ b/evergreen/apache.yml @@ -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: @@ -68,13 +72,4 @@ 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. diff --git a/extras/main.yml b/extras/main.yml index fbf68540e..108b4a812 100644 --- a/extras/main.yml +++ b/extras/main.yml @@ -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 index 000000000..02b9c268a --- /dev/null +++ b/extras/service-files/evergreen-reporter.service.j2 @@ -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 index 000000000..ede746b7f --- /dev/null +++ b/extras/service-files/opensrf.service.j2 @@ -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 index 000000000..e60af8aed --- /dev/null +++ b/extras/services.yml @@ -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 diff --git a/extras/start.yml b/extras/start.yml index 9929658bf..74913b951 100644 --- a/extras/start.yml +++ b/extras/start.yml @@ -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 @@ -12,6 +18,13 @@ 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 + diff --git a/opensrf/websockets.yml b/opensrf/websockets.yml index 82e978f32..1cbc4d49e 100644 --- a/opensrf/websockets.yml +++ b/opensrf/websockets.yml @@ -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 diff --git a/settings.yml b/settings.yml index bf169220a..90e401057 100644 --- a/settings.yml +++ b/settings.yml @@ -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 -- 2.11.0