Bläddra i källkod

Add Commento to blog task and add example index page for webhosting.

Thomas Buck 5 år sedan
förälder
incheckning
30832be156

+ 1
- 0
README.md Visa fil

@@ -34,6 +34,7 @@ What do you get if you point Sovereign at a server? All kinds of good stuff!
34 34
 -   [Monit](http://mmonit.com/monit/) to keep everything running smoothly (and alert you when it’s not).
35 35
 -   Web hosting (ex: for your blog) via [Apache](https://www.apache.org/).
36 36
 -   Statistics for the website using [Fathom](https://github.com/usefathom/fathom).
37
+-   Comments for the website using [Commento](https://gitlab.com/commento/commento).
37 38
 -   Firewall management via [Uncomplicated Firewall (ufw)](https://wiki.ubuntu.com/UncomplicatedFirewall).
38 39
 -   Intrusion prevention via [fail2ban](http://www.fail2ban.org/) and rootkit detection via [rkhunter](http://rkhunter.sourceforge.net).
39 40
 -   SSH configuration preventing root login and insecure password authentication

+ 20
- 7
roles/blog/defaults/main.yml Visa fil

@@ -3,16 +3,29 @@ secret_root: '{{ inventory_dir | realpath }}'
3 3
 secret_name: 'secret'
4 4
 secret: '{{ secret_root + "/" + secret_name }}'
5 5
 
6
-# must match values in roles/common
7
-db_admin_username: 'postgres'
8
-db_admin_password: "{{ lookup('password', secret + '/' + 'db_admin_password length=32') }}"
6
+fathom_admin_username: "{{ admin_email }}"
7
+fathom_admin_password: "{{ lookup('password', secret + '/' + 'fathom_admin_password length=32') }}"
8
+
9
+fathom_version: '1.2.1'
10
+fathom_release: "https://github.com/usefathom/fathom/releases/download/v{{ fathom_version }}/fathom_{{ fathom_version }}_linux_amd64.tar.gz"
9 11
 
10 12
 fathom_db_username: 'fathom'
11 13
 fathom_db_password: "{{ lookup('password', secret + '/' + 'fathom_db_password length=32') }}"
12 14
 fathom_db_database: 'fathom'
13
-fathom_admin_username: "{{ admin_email }}"
14
-fathom_admin_password: "{{ lookup('password', secret + '/' + 'fathom_admin_password length=32') }}"
15
+
15 16
 fathom_internal_port: '9000'
16 17
 fathom_secret: "{{ lookup('password', secret + '/' + 'fathom_secret length=32') }}"
17
-fathom_version: '1.2.1'
18
-fathom_release: "https://github.com/usefathom/fathom/releases/download/v{{ fathom_version }}/fathom_{{ fathom_version }}_linux_amd64.tar.gz"
18
+
19
+commento_version: '1.6.2'
20
+commento_release: "https://commento-release.s3.amazonaws.com/commento-linux-amd64-v{{ commento_version }}.tar.gz"
21
+
22
+commento_subdomain: 'comments'
23
+commento_internal_port: '9100'
24
+
25
+commento_db_username: 'commentouser'
26
+commento_db_password: "{{ lookup('password', secret + '/' + 'commento_db_password length=32') }}"
27
+commento_db_database: 'commento'
28
+
29
+# must match values in roles/common
30
+db_admin_username: 'postgres'
31
+db_admin_password: "{{ lookup('password', secret + '/' + 'db_admin_password length=32') }}"

+ 9
- 0
roles/blog/tasks/blog.yml Visa fil

@@ -17,6 +17,15 @@
17 17
   command: a2enconf well-known.conf creates=/etc/apache2/conf-enabled/well-known.conf.conf
18 18
   notify: restart apache
19 19
 
20
+- name: Create an example blog index page
21
+  template:
22
+    src=var_www_blog_index.j2
23
+    dest={{ item.doc_root }}/index.html
24
+    owner=www-data
25
+    group=www-data
26
+    force=no
27
+  with_items: "{{ virtual_domains }}"
28
+
20 29
 - name: Create the Apache blog sites config files
21 30
   template:
22 31
     src=etc_apache2_sites-available_blog.j2

+ 74
- 0
roles/blog/tasks/commento.yml Visa fil

@@ -0,0 +1,74 @@
1
+- name: Create temporary commento directories
2
+  file: state=directory path={{ item }}
3
+  with_items:
4
+    - /root/commento
5
+    - /root/commento/commento-{{ commento_version }}
6
+
7
+- name: Download commento {{ commento_version }} release
8
+  get_url:
9
+    url="{{ commento_release }}"
10
+    dest=/root/commento/commento-{{ commento_version }}.tar.gz
11
+
12
+- name: Decompress commento release
13
+  unarchive: src=/root/commento/commento-{{ commento_version }}.tar.gz
14
+             dest=/root/commento/commento-{{ commento_version }} copy=no
15
+             creates=/root/commento/commento-{{ commento_version }}/commento
16
+
17
+- name: Create commento working directory
18
+  file: state=directory path=/home/{{ main_user_name }}/commento
19
+
20
+- name: Stop old commento instance
21
+  service: name=commento state=stopped
22
+  ignore_errors: True
23
+
24
+- name: Copy commento data to working directory
25
+  shell: cp -r commento/commento-{{ commento_version }}/* /home/{{ main_user_name }}/commento/ chdir=/root
26
+
27
+- name: Setup permissions for commento
28
+  file: path=/home/{{ main_user_name }}/commento owner={{ main_user_name }} group=www-data recurse=yes
29
+
30
+- name: Add commento postgres user
31
+  postgresql_user:
32
+    login_host=localhost
33
+    login_user={{ db_admin_username }}
34
+    login_password="{{ db_admin_password }}"
35
+    name={{ commento_db_username }}
36
+    password="{{ commento_db_password }}"
37
+    encrypted=yes
38
+    state=present
39
+
40
+- name: Create commento database
41
+  postgresql_db:
42
+    login_host=localhost
43
+    login_user={{ db_admin_username }}
44
+    login_password="{{ db_admin_password }}"
45
+    name={{ commento_db_database }}
46
+    state=present
47
+    owner={{ commento_db_username }}
48
+
49
+- name: Add systemd service to start commento automatically
50
+  template:
51
+    src=etc_systemd_system_commento.j2
52
+    dest=/etc/systemd/system/commento.service
53
+    owner=root
54
+    group=root
55
+
56
+- name: Register new commento service
57
+  systemd: name=commento daemon_reload=yes enabled=yes
58
+
59
+- name: Start new commento instance
60
+  service: name=commento state=started
61
+
62
+- name: Create the Apache Commento sites config files
63
+  template:
64
+    src=etc_apache2_sites-available_commento.j2
65
+    dest=/etc/apache2/sites-available/commento_{{ item.name }}.conf
66
+    owner=root
67
+    group=root
68
+  notify: restart apache
69
+  with_items: "{{ virtual_domains }}"
70
+
71
+- name: Enable Apache sites (creates new sites-enabled symlinks)
72
+  command: a2ensite commento_{{ item }}.conf creates=/etc/apache2/sites-enabled/commento_{{ item }}.conf
73
+  notify: restart apache
74
+  with_items: "{{ virtual_domains | json_query('[*].name') }}"

+ 1
- 0
roles/blog/tasks/main.yml Visa fil

@@ -1,2 +1,3 @@
1 1
 - include: blog.yml tags=blog
2 2
 - include: fathom.yml tags=blog
3
+- include: commento.yml tags=blog

+ 20
- 0
roles/blog/templates/etc_apache2_sites-available_commento.j2 Visa fil

@@ -0,0 +1,20 @@
1
+<VirtualHost *:80>
2
+    ServerName {{ commento_subdomain }}.{{ item.name }}
3
+
4
+    Redirect temp / https://{{ commento_subdomain }}.{{ item.name }}/
5
+</VirtualHost>
6
+
7
+<VirtualHost *:443>
8
+    ServerName {{ commento_subdomain }}.{{ item.name }}
9
+
10
+    SSLEngine               On
11
+    DocumentRoot            "{{ item.doc_root }}"
12
+    DirectoryIndex          index.html
13
+    Options                 -Indexes
14
+    HostnameLookups         Off
15
+
16
+    ProxyRequests           On
17
+    ProxyPreserveHost       On
18
+    ProxyPass               / http://localhost:{{ commento_internal_port }}/
19
+    ProxyPassReverse        / http://localhost:{{ commento_internal_port }}/
20
+</VirtualHost>

+ 24
- 0
roles/blog/templates/etc_systemd_system_commento.j2 Visa fil

@@ -0,0 +1,24 @@
1
+[Unit]
2
+Description=Commento daemon service
3
+After=network.target postgresql.service
4
+
5
+[Service]
6
+Type=simple
7
+User={{ main_user_name }}
8
+Restart=always
9
+RestartSec=3
10
+WorkingDirectory=/home/{{ main_user_name }}/commento
11
+ExecStart=/home/{{ main_user_name }}/commento/commento
12
+Environment=COMMENTO_ORIGIN=https://{{ commento_subdomain }}.{{ domain }}
13
+Environment=COMMENTO_PORT={{ commento_internal_port }}
14
+Environment=COMMENTO_POSTGRES=postgres://{{ commento_db_username }}:{{ commento_db_password }}@localhost:5432/{{ commento_db_database }}?sslmode=disable
15
+Environment=COMMENTO_STATIC=/home/{{ main_user_name }}/commento
16
+Environment=COMMENTO_BIND_ADDRESS=127.0.0.1
17
+Environment=COMMENTO_SMTP_HOST=localhost
18
+Environment=COMMENTO_SMTP_PORT=25
19
+Environment=COMMENTO_SMTP_USERNAME=example@gmail.com
20
+Environment=COMMENTO_SMTP_PASSWORD=hunter2
21
+Environment=COMMENTO_SMTP_FROM_ADDRESS=no-reply@{{ commento_subdomain }}.{{ domain }}
22
+
23
+[Install]
24
+WantedBy=multi-user.target

+ 31
- 0
roles/blog/templates/var_www_blog_index.j2 Visa fil

@@ -0,0 +1,31 @@
1
+<html>
2
+	<head>
3
+		<title>{{ item.name }}</title>
4
+	</head>
5
+	<body>
6
+		<h1>{{ item.name }}</h1>
7
+		<p>Bitte gehen Sie weiter, hier gibt es nichts zu sehen!</p>
8
+		<p>Please go along, there is nothing to see here!</p>
9
+
10
+		<!-- Commento comments (Disqus alternative) -->
11
+		<div id="commento"></div>
12
+		<script src="https://{{ commento_subdomain }}.{{ domain }}/js/commento.js"></script>
13
+
14
+		<!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
15
+		<!-- TODO: replace 'JTPIK' with your correct site-id in fathom -->
16
+		<script>
17
+(function(f, a, t, h, o, m){
18
+	a[h]=a[h]||function(){
19
+		(a[h].q=a[h].q||[]).push(arguments)
20
+	};
21
+	o=f.createElement('script'),
22
+	m=f.getElementsByTagName('script')[0];
23
+	o.async=1; o.src=t; o.id='fathom-script';
24
+	m.parentNode.insertBefore(o,m)
25
+})(document, window, '//fathom.{{ domain }}/tracker.js', 'fathom');
26
+fathom('set', 'siteId', 'JTPIK');
27
+fathom('trackPageview');
28
+		</script>
29
+		<!-- / Fathom -->
30
+	</body>
31
+</html>

+ 1
- 1
roles/common/files/letsencrypt-gencert Visa fil

@@ -17,7 +17,7 @@ for domain in "$@"; do
17 17
   fi
18 18
 
19 19
   # subdomains - www.foo.com mail.foo.com ...
20
-  for sub in www mail autoconfig fathom news cloud git matrix status social; do
20
+  for sub in www mail autoconfig fathom news cloud git matrix status social comments; do
21 21
     # only add if the DNS entry for the subdomain does actually exist
22 22
     if (getent hosts $sub.$domain > /dev/null); then
23 23
       if [ -z "$d" ]; then

+ 8
- 0
roles/monitoring/files/etc_monit_conf.d_commento Visa fil

@@ -0,0 +1,8 @@
1
+check process commento matching "commento"
2
+  group www
3
+  start program = "/bin/systemctl start commento"
4
+  stop program = "/bin/systemctl stop commento"
5
+  if failed port 9100 protocol http
6
+    with timeout 10 seconds
7
+    then restart
8
+  if 5 restarts within 5 cycles then timeout

+ 9
- 0
roles/monitoring/tasks/monit.yml Visa fil

@@ -48,6 +48,10 @@
48 48
   stat: path=/home/mastodon/mastodon
49 49
   register: mastodon_config_file
50 50
 
51
+- name: Determine if Commento is installed
52
+  stat: path=/home/{{ main_user_name }}/commento/commento
53
+  register: commento_config_file
54
+
51 55
 - name: Copy ZNC monit service config files into place
52 56
   copy: src=etc_monit_conf.d_znc dest=/etc/monit/conf.d/znc
53 57
   notify: restart monit
@@ -88,6 +92,11 @@
88 92
   notify: restart monit
89 93
   when: mastodon_config_file.stat.exists == True
90 94
 
95
+- name: Copy Commento monit service config files into place
96
+  copy: src=etc_monit_conf.d_commento dest=/etc/monit/conf.d/commento
97
+  notify: restart monit
98
+  when: commento_config_file.stat.exists == True
99
+
91 100
 - name: Copy monit service config files into place
92 101
   copy: src=etc_monit_conf.d_{{ item }} dest=/etc/monit/conf.d/{{ item }}
93 102
   with_items:

Laddar…
Avbryt
Spara