From bc5ad21d32291998445421410dd78adbd36abb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 27 Feb 2018 12:05:11 +0100 Subject: [PATCH] Manage services for the lists var (flexlm__licences) Also allow to manage several licences on a same host (close #1) --- CHANGELOG.md | 2 + README.md | 37 ++++++++++--------- defaults/main.yml | 9 +---- handlers/main.yml | 11 ++++-- tasks/main.yml | 24 ++++++++---- .../etc/systemd/system/flexlm.service.j2 | 6 +-- 6 files changed, 50 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e6513..c42e56c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ### Features * Add a way to provide vendor daemon binaries and licence file. +* Manage services for the lists var (flexlm__licences). +* Allow to manage several licences on a same host (close #1). ## v1.0 diff --git a/README.md b/README.md index ff30a57..1d650c8 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,10 @@ 2. [Role Variables](#role-variables) 3. [Example Playbook](#example-playbook) 4. [Configuration](#configuration) -5. [Development](#development) -6. [License](#license) -7. [Author Information](#author-information) +5. [Known Issues](#known-issues) +6. [Development](#development) +7. [License](#license) +8. [Author Information](#author-information) ## Overview @@ -27,10 +28,6 @@ A role to manage Flexlm daemon. * **flexlm__licences** : Lists to manage vendor daemon and licence files [default : `[]`]. * **flexlm__service_manage** : If Licence Manager service should be managed with this role [default : `True`]. * **flexlm__service_enabled** : If Licence Manager service should be enable at startup [default : `True`]. -* **flexlm__service_name** : Service name [default : `flexlm`]. -* **flexlm__service_description** : Description of the systemd unit [default : `flexlm Licence Manager`]. -* **flexlm__service_working_directory** : Working directory of the systemd unit [default : `/opt/flexlm/VENDOR`]. -* **flexlm__service_unit_path** : Systemd unit path [default : `/etc/systemd/system/{{ flexlm__service_name }}.service`]. * **flexlm__service_unit_content** : Template used to generate the previous file [default : `etc/systemd/system/flexlm.service.j2`]. ## Example Playbook @@ -43,28 +40,28 @@ A role to manage Flexlm daemon. - role: ipr-cnrs.flexlm ``` -* Manage Flexlm to provide Intel Fortran : +* Manage Flexlm to provide Intel Fortran (without binaries) : ``` yaml - hosts: intel-lm roles: - role: ipr-cnrs.flexlm - flexlm__service_working_directory: '/opt/intel/bin' - flexlm__licence_file: '/opt/intel/etc/license.lic' - flexlm__service_description: 'Licence Manager for Intel Fortran' + flexlm__licences: + - name: intel + description: 'flexlm Licence Manager for Matlab' + bin_path: '/opt/intel/bin' + lic_path: '/opt/matlab/etc/licence.lic' # need to be a file ``` -* Manage Flexlm to provide Matlab Licence and vendor daemon : +* Manage Flexlm to provide Matlab Licence and vendor daemon binaries : ```yaml - hosts: matlab-lm roles: - role: ipr-cnrs.flexlm - flexlm__service_working_directory: '/opt/matlab/bin' - flexlm__licence_file: '/opt/matlab/etc/license.lic' - flexlm__service_description: 'Licence Manager for Matlab' flexlm__licences: - name: matlab + description: 'flexlm Licence Manager for Matlab' bin_path: '/opt/matlab/bin' bin_src: '{{ inventory_dir + "/../resources/service/matlab-lm/bin/" }}' lic_path: '/opt/matlab/etc/licence.lic' # need to be a file @@ -76,12 +73,16 @@ A role to manage Flexlm daemon. This role will : * Copy the `lmgrd` and `lmutil` binaries to the client. * Create a specific user to launch daemon. -* Set up a systemd service. [Thanks to Kalebo instructions][kalebo instruction flexlm systemd]. -* Copy vendor daemon binaries to the host if specified. -* Copy licence file to the host if specified. +* Set up a systemd service (flexlm-NAME). [Thanks to Kalebo instructions][kalebo instruction flexlm systemd]. +* Copy vendor daemon binaries to the host if source is specified. +* Copy licence file to the host if source is specified. The `lmgrd` and `lmutil` binaries comes from [Mathworks][mathworks download url] in version **flexlm__lmgrd_version**. +## Known Issues + +* If a value of one licence change in **flexlm__licences** var, all services will be restarted. + ## Development This source code comes from our [Gogs instance][flexlm source] and the [Github repo][flexlm github] exist just to be able to send the role to Ansible Galaxy… diff --git a/defaults/main.yml b/defaults/main.yml index 39df3c3..cecceca 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,9 +16,6 @@ flexlm__lmutil_path: '/usr/local/bin/lmutil' # user flexlm__user_name: 'flexlm' -# licence -flexlm__licence_file: '/opt/flexlm/VENDOR/licence.lic' - # Lists to manage vendor daemon and licence files. # flexlm_licences: # - name: matlab @@ -27,14 +24,12 @@ flexlm__licence_file: '/opt/flexlm/VENDOR/licence.lic' # bin_src: '{{ inventory_dir + "/../resources/service/matlab-lm/bin/" }}' # lic_path: '/opt/matlab/etc/licence.lic' # lic_src: '{{ inventory_dir + "/../resources/hosts/matlab-lm/opt/matlab/etc/licence.lic" }}' +# #service: False +# ports: [ '27000', '33188' ] # not used right now flexlm__licences: [] # service flexlm__service_manage: True flexlm__service_enabled: True -flexlm__service_name: 'flexlm' -flexlm__service_description: 'flexlm Licence Manager' -flexlm__service_working_directory: '/opt/flexlm/VENDOR' -flexlm__service_unit_path: '/etc/systemd/system/{{ flexlm__service_name }}.service' flexlm__service_unit_content: 'etc/systemd/system/flexlm.service.j2' diff --git a/handlers/main.yml b/handlers/main.yml index 8753d0b..e0245da 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,10 @@ --- # handlers file for flexlm -- name: restart flexlm service - service: name={{ flexlm__service_name }} state=restarted - when: flexlm__service_manage +- name: restart flexlm services + service: + name: '{{ "flexlm-" + item.name }}' + state: restarted + with_flattened: + - '{{ flexlm__licences }}' + when: ( flexlm__service_manage and + ( item.service | d(True) )) diff --git a/tasks/main.yml b/tasks/main.yml index ae6c328..f31974c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -58,6 +58,7 @@ with_flattened: - '{{ flexlm__licences }}' when: (item.bin_src|d()) + notify: ['restart flexlm services'] - name: Add licence file copy: @@ -69,33 +70,40 @@ with_flattened: - '{{ flexlm__licences }}' when: (item.lic_src|d()) + notify: ['restart flexlm services'] # }}} # service {{{ -- name: SERVICE '{{ flexlm__service_name }}' systemd unit +- name: Add systemd unit template: src: '{{ flexlm__service_unit_content }}' - dest: '{{ flexlm__service_unit_path }}' + dest: '{{ "/etc/systemd/system/flexlm-" + item.name + ".service" }}' owner: 'root' group: 'root' mode: '0644' register: flexlm__register_systemd_service - notify: ['restart flexlm service'] - when: flexlm__service_manage + notify: ['restart flexlm services'] + with_flattened: + - '{{ flexlm__licences }}' + when: ( flexlm__service_manage and + ( item.service | d(True) )) - name: Reload systemd daemons command: systemctl daemon-reload - notify: ['restart flexlm service'] + notify: ['restart flexlm services'] when: (flexlm__service_manage and flexlm__register_systemd_service|changed) -- name: SERVICE manage '{{ flexlm__service_name }}' +- name: SERVICE manage services service: - name: '{{ flexlm__service_name }}' + name: '{{ "flexlm-" + item.name }}' state: started enabled: '{{ flexlm__service_enabled }}' - when: flexlm__service_manage + with_flattened: + - '{{ flexlm__licences }}' + when: ( flexlm__service_manage and + ( item.service | d(True) )) # }}} diff --git a/templates/etc/systemd/system/flexlm.service.j2 b/templates/etc/systemd/system/flexlm.service.j2 index 440d032..e548b4c 100644 --- a/templates/etc/systemd/system/flexlm.service.j2 +++ b/templates/etc/systemd/system/flexlm.service.j2 @@ -1,13 +1,13 @@ # {{ ansible_managed }} [Unit] -Description={{ flexlm__service_description }} +Description={{ item.description | d("flexlm Licence Manager for " + item.name) }} After=network.target [Service] Type=simple User={{ flexlm__user_name }} -WorkingDirectory={{ flexlm__service_working_directory }} -ExecStart={{ flexlm__lmgrd_path }} -z -c {{ flexlm__licence_file }} +WorkingDirectory={{ item.bin_path | d("/opt/" + item.name + "/bin") }} +ExecStart={{ flexlm__lmgrd_path }} -z -c {{ item.lic_path | d("/opt/" + item.name + "/etc/licence.lic") }} SuccessExitStatus=15 Restart=always RestartSec=30