From 56cf700fd0e0f7a3ba4fdba7cf9c1d7a876fa840 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Thu, 22 Feb 2018 22:02:06 -0500 Subject: [PATCH] Add systemd support for geard Include the ability for a user to run geard. Change-Id: I6a075da4f1b094930948aad3ebfa912bcd598d42 Signed-off-by: Paul Belanger --- defaults/main.yaml | 13 ++++ tasks/service.yaml | 72 ++++++++++++++++++- templates/etc/systemd/system/gear.service | 15 ++++ .../system/gear.service.d/override.conf | 3 + vars/redhat.yaml | 8 +++ vars/ubuntu-xenial.yaml | 8 +++ 6 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 templates/etc/systemd/system/gear.service create mode 100644 templates/etc/systemd/system/gear.service.d/override.conf diff --git a/defaults/main.yaml b/defaults/main.yaml index 6383c12..18effd1 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -41,3 +41,16 @@ gear_pip_name: gear # gear_pip_virtualenv: # tasks/service.yaml +gear_file_gear_service_manage: true +gear_file_gear_service_group: root +gear_file_gear_service_owner: root + +gear_file_gear_service_config_manage: true +gear_file_gear_service_config_group: root +gear_file_gear_service_config_owner: root + +gear_service_gear_daemon_reload: true +gear_service_gear_enabled: yes +gear_service_gear_manage: true +gear_service_gear_name: gear +gear_service_gear_state: started diff --git a/tasks/service.yaml b/tasks/service.yaml index 71e9e77..386bb4b 100644 --- a/tasks/service.yaml +++ b/tasks/service.yaml @@ -1,4 +1,4 @@ -# Copyright 2017 Red Hat, Inc. +# Copyright 2018 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,3 +12,73 @@ # License for the specific language governing permissions and limitations # under the License. --- +- name: Define gear_file_gear_service_dest. + set_fact: + gear_file_gear_service_dest: "{{ __gear_file_gear_service_dest }}" + when: gear_file_gear_dest is not defined + +- name: Define gear_file_gear_service_mode. + set_fact: + gear_file_gear_service_mode: "{{ __gear_file_gear_service_mode }}" + when: gear_file_gear_service_mode is not defined + +- name: Define gear_file_gear_service_src. + set_fact: + gear_file_gear_service_src: "{{ __gear_file_gear_service_src }}" + when: gear_file_gear_service_src is not defined + +- name: Define gear_file_gear_service_config_dest. + set_fact: + gear_file_gear_service_config_dest: "{{ __gear_file_gear_service_config_dest }}" + when: gear_file_gear_service_config_dest is not defined + +- name: Define gear_file_gear_service_config_mode. + set_fact: + gear_file_gear_service_config_mode: "{{ __gear_file_gear_service_config_mode }}" + when: gear_file_gear_service_config_mode is not defined + +- name: Define gear_file_gear_service_config_src. + set_fact: + gear_file_gear_service_config_src: "{{ __gear_file_gear_service_config_src }}" + when: gear_file_gear_service_config_src is not defined + +- name: Install gear service script into place. + become: yes + template: + dest: "{{ gear_file_gear_service_dest }}" + group: "{{ gear_file_gear_service_group }}" + mode: "{{ gear_file_gear_service_mode }}" + owner: "{{ gear_file_gear_service_owner }}" + src: "{{ gear_file_gear_service_src }}" + register: gear_file_gear_service + when: gear_file_gear_service_manage + +- name: Create gear service config directory. + become: yes + file: + group: "{{ gear_file_gear_service_config_group }}" + owner: "{{ gear_file_gear_service_config_owner }}" + path: "{{ gear_file_gear_service_dest }}.d" + state: directory + when: gear_file_gear_service_config_manage + +- name: Install gear service config into place. + become: yes + template: + dest: "{{ gear_file_gear_service_config_dest }}" + group: "{{ gear_file_gear_service_config_group }}" + mode: "{{ gear_file_gear_service_config_mode }}" + owner: "{{ gear_file_gear_service_config_owner }}" + src: "{{ gear_file_gear_service_config_src }}" + register: gear_file_gear_service_config + when: gear_file_gear_service_config_manage + +- name: Enable gear service. + become: yes + systemd: + daemon_reload: "{{ gear_service_gear_daemon_reload }}" + enabled: "{{ gear_service_gear_enabled }}" + name: "{{ gear_service_gear_name }}" + state: "{{ gear_service_gear_state }}" + register: gear_service_gear + when: gear_service_gear_manage diff --git a/templates/etc/systemd/system/gear.service b/templates/etc/systemd/system/gear.service new file mode 100644 index 0000000..774f34b --- /dev/null +++ b/templates/etc/systemd/system/gear.service @@ -0,0 +1,15 @@ +[Unit] +Description=Gear Service +After=syslog.target network.target + +[Service] +Type=simple +# The prefix used when gear was installed. Be sure to update this +# value if you are using a virtualenv. +Environment="PREFIX=/usr/local" +Group=gear +User=gear +ExecStart=/bin/sh -c "${PREFIX}/bin/geard -d" + +[Install] +WantedBy=multi-user.target diff --git a/templates/etc/systemd/system/gear.service.d/override.conf b/templates/etc/systemd/system/gear.service.d/override.conf new file mode 100644 index 0000000..602ac8e --- /dev/null +++ b/templates/etc/systemd/system/gear.service.d/override.conf @@ -0,0 +1,3 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# diff --git a/vars/redhat.yaml b/vars/redhat.yaml index ebf8894..fdd129c 100644 --- a/vars/redhat.yaml +++ b/vars/redhat.yaml @@ -13,3 +13,11 @@ # under the License. --- __gear_build_depends: [] + +__gear_file_gear_service_dest: /etc/systemd/system/gear.service +__gear_file_gear_service_mode: 0644 +__gear_file_gear_service_src: etc/systemd/system/gear.service + +__gear_file_gear_service_config_dest: /etc/systemd/system/gear.service.d/override.conf +__gear_file_gear_service_config_mode: 0644 +__gear_file_gear_service_config_src: etc/systemd/system/gear.service.d/override.conf diff --git a/vars/ubuntu-xenial.yaml b/vars/ubuntu-xenial.yaml index ebf8894..fdd129c 100644 --- a/vars/ubuntu-xenial.yaml +++ b/vars/ubuntu-xenial.yaml @@ -13,3 +13,11 @@ # under the License. --- __gear_build_depends: [] + +__gear_file_gear_service_dest: /etc/systemd/system/gear.service +__gear_file_gear_service_mode: 0644 +__gear_file_gear_service_src: etc/systemd/system/gear.service + +__gear_file_gear_service_config_dest: /etc/systemd/system/gear.service.d/override.conf +__gear_file_gear_service_config_mode: 0644 +__gear_file_gear_service_config_src: etc/systemd/system/gear.service.d/override.conf