From 94672dbdb9654d6d5609688b8f94a7ffcf1dc9b0 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 12 Apr 2017 11:43:01 +0200 Subject: [PATCH] library/roles/springboot-config: Installs a startup script (upstart only right now) and a logrotate file to support springboot applications. --- springboot-config/defaults/main.yml | 6 ++++++ springboot-config/tasks/main.yml | 13 +++++++++++++ .../templates/springboot-logrotate.j2 | 8 ++++++++ .../templates/springboot-upstart.conf.j2 | 17 +++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 springboot-config/defaults/main.yml create mode 100644 springboot-config/tasks/main.yml create mode 100644 springboot-config/templates/springboot-logrotate.j2 create mode 100644 springboot-config/templates/springboot-upstart.conf.j2 diff --git a/springboot-config/defaults/main.yml b/springboot-config/defaults/main.yml new file mode 100644 index 00000000..79b5ca4a --- /dev/null +++ b/springboot-config/defaults/main.yml @@ -0,0 +1,6 @@ +--- +springboot_config: False +springboot_apps: + - { name: 'foo', log_dir: '/var/log/foo', install_dir: '/usr/lib/foo', state: 'present', user: 'foo', java_opts: '' } + + diff --git a/springboot-config/tasks/main.yml b/springboot-config/tasks/main.yml new file mode 100644 index 00000000..d5194b5c --- /dev/null +++ b/springboot-config/tasks/main.yml @@ -0,0 +1,13 @@ +--- +- block: + - name: Install the springboot app upstart init file + template: src=springboot-upstart.conf.j2 dest=/etc/init/{{ item.name }}.conf owner=root group=root mode=0644 + with_items: '{{ springboot_apps }}' + when: is_trusty + + - name: Install the springboot logrotate configuration + template: src=springboot-logrotate.j2 dest=/etc/logrotate.d/{{ item.name }} owner=root group=root mode=0444 + with_items: '{{ springboot_apps }}' + + when: springboot_config + tags: [ 'springboot', 'springboot_config' ] diff --git a/springboot-config/templates/springboot-logrotate.j2 b/springboot-config/templates/springboot-logrotate.j2 new file mode 100644 index 00000000..4e12929e --- /dev/null +++ b/springboot-config/templates/springboot-logrotate.j2 @@ -0,0 +1,8 @@ +{{ item.log_dir }}/{{ item.name }}.log { + copytruncate + daily + rotate 10 + compress + missingok + create 640 {{ item.user }} adm +} diff --git a/springboot-config/templates/springboot-upstart.conf.j2 b/springboot-config/templates/springboot-upstart.conf.j2 new file mode 100644 index 00000000..6d003355 --- /dev/null +++ b/springboot-config/templates/springboot-upstart.conf.j2 @@ -0,0 +1,17 @@ +# {{ item.name }} + +description "{{ item.name }}" + +start on runlevel [2345] +stop on runlevel [!2345] +respawn +respawn limit 10 5 + +setuid {{ item.user }} +setgid {{ item.user }} + +script + cd {{ item.install_dir }} + exec java {{ item.java_opts }} -jar ./{{ item.name }}.jar +end script +