-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathserver.yml
117 lines (100 loc) · 2.91 KB
/
server.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
- hosts: backend
gather_facts: no
vars:
- app_source_zip: "apps/server.zip"
- app_source_zip_remote: "server.zip"
tasks:
- name: Install java11
become: yes
apt:
name: default-jre
state: latest
- name: Install unzip
become: yes
apt:
name: unzip
state: latest
- name: Build the application
retries: 10
delay: 5
shell: "./scripts/build-server.sh {{ app_source_name }}"
delegate_to: 127.0.0.1
- name: Upload the application
synchronize:
src: "{{ app_source_zip }}"
dest: "{{ app_source_zip_remote }}"
# Registering the service before unpacking the app allows to make sure the app is stopped
# on the first deployment.
- name: Add the systemd service
become: yes
template:
src: "{{ app_systemd_service_source }}"
dest: "/etc/systemd/system/{{ app_systemd_service_name }}.service"
- name: Pick up systemd changes
become: yes
systemd:
daemon_reload: yes
- name: Make sure the application is stopped
become: yes
systemd:
name: "{{ app_systemd_service_name }}"
state: stopped
# This is crucial to avoid polluting the classpath with old jars after upgrading dependencies
- name: Delete old application (important!)
become: yes
file:
path: "{{ app_home }}/{{ app_directory_name }}"
state: absent
- name: Create the app group
become: yes
group:
name: "{{ app_group }}"
state: present
- name: Create the app user
become: yes
user:
name: "{{ app_user }}"
group: "{{ app_group }}"
state: present
system: yes
- name: Create the app directory
become: yes
file:
path: "{{ app_home }}"
state: directory
owner: "{{ app_user }}"
group: "{{ app_group }}"
- name: Unpack the application
become: yes
unarchive:
remote_src: yes
src: "{{ app_source_zip_remote }}"
dest: "{{ app_home }}"
owner: "{{ app_user }}"
group: "{{ app_group }}"
- name: Set the application config
become: yes
template:
src: "{{ app_env_config_source }}"
dest: "{{ app_env_config_file }}"
owner: "{{ app_user }}"
group: "{{ app_group }}"
- name: Set the application files permissions
become: yes
file:
dest: "{{ app_home }}"
owner: "{{ app_user }}"
group: "{{ app_group }}"
recurse: yes
- name: Make sure the application is started
become: yes
systemd:
name: "{{ app_systemd_service_name }}"
state: started
- name: Enable the application to run on system startup
become: yes
systemd:
name: "{{ app_systemd_service_name }}"
enabled: yes
# TODO: Check service is healthy by querying localhost:9000/health