Procházet zdrojové kódy

add experimental rocket.chat role

Thomas Buck před 3 roky
rodič
revize
eadff101f8

+ 14
- 0
roles/rocketchat/DESIGN.md Zobrazit soubor

@@ -0,0 +1,14 @@
1
+# Design Description for Rocket.Chat Role
2
+
3
+This role installs Rocket.Chat using the official "manual installation".
4
+
5
+MongoDB is installed using the official upstream debian packages. The most-recent version is used automatically.
6
+
7
+Node.js v12.x is installed using the official upstream debian packages.
8
+
9
+https://docs.rocket.chat/installing-and-updating/manual-installation/debian
10
+https://docs.rocket.chat/installing-and-updating/manual-installation/configuring-ssl-reverse-proxy
11
+
12
+https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/
13
+
14
+https://github.com/nodesource/distributions/blob/master/README.md

+ 7
- 0
roles/rocketchat/defaults/main.yml Zobrazit soubor

@@ -0,0 +1,7 @@
1
+rocketchat_subdomain: "chat"
2
+rocketchat_domain: "{{ rocketchat_subdomain }}.{{ domain }}"
3
+
4
+rocketchat_internal_port: "3042"
5
+
6
+rocketchat_version: "3.15.0"
7
+rocketchat_release: "https://cdn-download.rocket.chat/build/rocket.chat-{{ rocketchat_version }}.tgz"

+ 44
- 0
roles/rocketchat/files/etc_mongod.conf Zobrazit soubor

@@ -0,0 +1,44 @@
1
+# mongod.conf
2
+
3
+# for documentation of all options, see:
4
+#   http://docs.mongodb.org/manual/reference/configuration-options/
5
+
6
+# Where and how to store data.
7
+storage:
8
+  dbPath: /var/lib/mongodb
9
+  journal:
10
+    enabled: true
11
+  engine: wiredTiger
12
+#  mmapv1:
13
+#  wiredTiger:
14
+
15
+# where to write logging data.
16
+systemLog:
17
+  destination: file
18
+  logAppend: true
19
+  path: /var/log/mongodb/mongod.log
20
+
21
+# network interfaces
22
+net:
23
+  port: 27017
24
+  bindIp: 127.0.0.1
25
+
26
+
27
+# how the process runs
28
+processManagement:
29
+  timeZoneInfo: /usr/share/zoneinfo
30
+
31
+#security:
32
+
33
+#operationProfiling:
34
+
35
+replication:
36
+  replSetName: rs01
37
+
38
+#sharding:
39
+
40
+## Enterprise-Only Options:
41
+
42
+#auditLog:
43
+
44
+#snmp:

+ 5
- 0
roles/rocketchat/handlers/main.yml Zobrazit soubor

@@ -0,0 +1,5 @@
1
+- name: restart apache
2
+  service: name=apache2 state=restarted
3
+
4
+- name: restart mongod
5
+  service: name=mongod state=restarted

+ 2
- 0
roles/rocketchat/tasks/main.yml Zobrazit soubor

@@ -0,0 +1,2 @@
1
+---
2
+- include: rocketchat.yml tags=rocketchat

+ 140
- 0
roles/rocketchat/tasks/rocketchat.yml Zobrazit soubor

@@ -0,0 +1,140 @@
1
+- name: Ensure repository key for MongoDB is in place for Rocket.Chat
2
+  apt_key: url=https://www.mongodb.org/static/pgp/server-4.4.asc state=present
3
+  tags:
4
+    - dependencies
5
+
6
+- name: Add MongoDB repository for Rocket.Chat
7
+  apt_repository: repo="deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.4 main"
8
+  tags:
9
+    - dependencies
10
+  when: ansible_distribution_version == '9'
11
+
12
+- name: Add MongoDB repository for Rocket.Chat
13
+  apt_repository: repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main"
14
+  tags:
15
+    - dependencies
16
+  when: ansible_distribution_version == '10'
17
+
18
+- name: Check if Node.js is installed
19
+  command: dpkg-query -l nodejs
20
+  register: nodejs_deb_check
21
+
22
+- name: Add Node.js repository for Rocket.Chat
23
+  shell: curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash -
24
+  when: nodejs_deb_check.stdout.find('no packages found') != -1
25
+
26
+- name: Install MongoDB and other Rocket.Chat dependencies
27
+  apt:
28
+    name: "{{ packages }}"
29
+    state: present
30
+    update_cache: yes
31
+  vars:
32
+    packages:
33
+    - build-essential
34
+    - mongodb-org
35
+    - nodejs
36
+    - fontconfig
37
+    - graphicsmagick
38
+  tags:
39
+    - dependencies
40
+
41
+- name: Install proper Node.js version and dependencies for Rocket.Chat
42
+  shell: sudo npm install -g inherits n && sudo n 12.18.4
43
+
44
+- name: Create temporary Rocket.Chat directory
45
+  file: state=directory path=/root/rocketchat
46
+
47
+- name: Download Rocket.Chat {{ rocketchat_version }} release
48
+  get_url:
49
+    url="{{ rocketchat_release }}"
50
+    dest=/root/rocketchat/rocketchat-{{ rocketchat_version }}.tar.gz
51
+
52
+- name: Check if temporary Rocket.Chat {{ rocketchat_version }} directory already exists
53
+  stat:
54
+    path: /root/rocketchat/{{ rocketchat_version }}
55
+  register: rocketchat_unpack_check
56
+
57
+- name: Create temporary Rocket.Chat {{ rocketchat_version }} directory
58
+  file: state=directory path=/root/rocketchat/{{ rocketchat_version }}
59
+
60
+- name: Unpack Rocket.Chat {{ rocketchat_version }} source
61
+  shell: tar xzvf /root/rocketchat/rocketchat-{{ rocketchat_version }}.tar.gz -C /root/rocketchat/{{ rocketchat_version }}
62
+  args:
63
+    chdir: /root/rocketchat
64
+    creates: /root/rocketchat/{{ rocketchat_version }}/bundle
65
+
66
+- name: Install Rocket.Chat {{ rocketchat_version }} source
67
+  shell: cd /root/rocketchat/{{ rocketchat_version }}/bundle/programs/server && npm install --unsafe-perm
68
+  when: not rocketchat_unpack_check.stat.exists
69
+
70
+- name: Create /usr/local/bin/Rocket.Chat
71
+  file: state=directory path=/usr/local/bin/Rocket.Chat
72
+
73
+- name: Stop old Rocket.Chat instance
74
+  service: name=rocketchat state=stopped
75
+  ignore_errors: True
76
+
77
+- name: Copy Rocket.Chat to /usr/local/bin/Rocket.Chat
78
+  shell: cp -R /root/rocketchat/{{ rocketchat_version }}/bundle/. /usr/local/bin/Rocket.Chat/
79
+
80
+- name: Add rocketchat group
81
+  group:
82
+    name: rocketchat
83
+    state: present
84
+
85
+- name: Add rocketchat user
86
+  user:
87
+    name: rocketchat
88
+    create_home: no
89
+    shell: /bin/bash
90
+    password_lock: yes
91
+    state: present
92
+    system: yes
93
+    group: rocketchat
94
+
95
+- name: Fix Rocket.Chat permissions
96
+  shell: sudo chown -R rocketchat:rocketchat /usr/local/bin/Rocket.Chat
97
+
98
+- name: Create the Rocket.Chat service file
99
+  template:
100
+    src=lib_systemd_system_rocketchat.j2
101
+    dest=/lib/systemd/system/rocketchat.service
102
+    owner=root
103
+    group=root
104
+
105
+- name: Add modified MongoDB config file for Rocket.Chat
106
+  copy:
107
+    src=etc_mongod.conf
108
+    dest=/etc/mongod.conf
109
+    owner=root
110
+    group=root
111
+  notify: restart mongod
112
+
113
+- name: Register new MongoDB service for Rocket.Chat
114
+  systemd: name=mongod daemon_reload=yes enabled=yes
115
+
116
+- name: Start new MongoDB instance for Rocket.Chat
117
+  service: name=mongod state=restarted
118
+
119
+- name: Initiate MongoDB replication set for Rocket.Chat
120
+  shell: sudo mongo --eval "if (rs.status().codeName == \"NotYetInitialized\") printjson(rs.initiate())"
121
+
122
+- name: Register new Rocket.Chat service
123
+  systemd: name=rocketchat daemon_reload=yes enabled=yes
124
+
125
+- name: Start new Rocket.Chat instance
126
+  service: name=rocketchat state=started
127
+
128
+- name: Create the Apache Rocket.Chat sites config files
129
+  template:
130
+    src=etc_apache2_sites-available_rocketchat.j2
131
+    dest=/etc/apache2/sites-available/rocketchat_{{ item.name }}.conf
132
+    owner=root
133
+    group=root
134
+  notify: restart apache
135
+  with_items: "{{ virtual_domains }}"
136
+
137
+- name: Enable Apache sites (creates new sites-enabled symlinks)
138
+  command: a2ensite rocketchat_{{ item }}.conf creates=/etc/apache2/sites-enabled/rocketchat_{{ item }}.conf
139
+  notify: restart apache
140
+  with_items: "{{ virtual_domains | json_query('[*].name') }}"

+ 29
- 0
roles/rocketchat/templates/etc_apache2_sites-available_rocketchat.j2 Zobrazit soubor

@@ -0,0 +1,29 @@
1
+<VirtualHost *:80>
2
+    ServerName {{ rocketchat_subdomain }}.{{ item.name }}
3
+
4
+    Redirect temp / https://{{ rocketchat_subdomain }}.{{ item.name }}/
5
+</VirtualHost>
6
+
7
+<VirtualHost *:443>
8
+    ServerName {{ rocketchat_subdomain }}.{{ item.name }}
9
+
10
+    SSLEngine               On
11
+    Options                 -Indexes
12
+    HostnameLookups         Off
13
+    LogLevel                warn
14
+    ErrorLog                /var/log/apache2/rocketchat.info-error_log
15
+    CustomLog               /var/log/apache2/rocketchat.info-access_log common
16
+
17
+
18
+    RewriteEngine On
19
+    RewriteCond %{HTTP:CONNECTION} Upgrade [NC]
20
+    RewriteCond %{HTTP:Upgrade} =websocket [NC]
21
+    RewriteRule /(.*)           ws://localhost:{{ rocketchat_internal_port }}/$1 [P,L]
22
+    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
23
+    RewriteRule /(.*)           http://localhost:{{ rocketchat_internal_port }}/$1 [P,L]
24
+
25
+    ProxyRequests           Off
26
+    ProxyPreserveHost       On
27
+    ProxyPass               / http://localhost:{{ rocketchat_internal_port }}/
28
+    ProxyPassReverse        / http://localhost:{{ rocketchat_internal_port }}/
29
+</VirtualHost>

+ 12
- 0
roles/rocketchat/templates/lib_systemd_system_rocketchat.j2 Zobrazit soubor

@@ -0,0 +1,12 @@
1
+[Unit]
2
+Description=The Rocket.Chat server
3
+After=network.target remote-fs.target nss-lookup.target apache2.service mongod.service
4
+[Service]
5
+ExecStart=/usr/local/bin/node /usr/local/bin/Rocket.Chat/main.js
6
+StandardOutput=syslog
7
+StandardError=syslog
8
+SyslogIdentifier=rocketchat
9
+User=rocketchat
10
+Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01 MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 ROOT_URL=https://{{ rocketchat_domain }}/ PORT={{ rocketchat_internal_port }}
11
+[Install]
12
+WantedBy=multi-user.target

Loading…
Zrušit
Uložit