Selaa lähdekoodia

Added Fathom statistics tracker to blog task

Thomas Buck 5 vuotta sitten
vanhempi
commit
04ba7ad539

+ 2
- 0
README.md Näytä tiedosto

@@ -32,6 +32,7 @@ What do you get if you point Sovereign at a server? All kinds of good stuff!
32 32
 -   [Monit](http://mmonit.com/monit/) to keep everything running smoothly (and alert you when it’s not).
33 33
 -   [collectd](http://collectd.org/) to collect system statistics.
34 34
 -   Web hosting (ex: for your blog) via [Apache](https://www.apache.org/).
35
+-   Statistics for the website using [Fathom](https://github.com/usefathom/fathom).
35 36
 -   Firewall management via [Uncomplicated Firewall (ufw)](https://wiki.ubuntu.com/UncomplicatedFirewall).
36 37
 -   Intrusion prevention via [fail2ban](http://www.fail2ban.org/) and rootkit detection via [rkhunter](http://rkhunter.sourceforge.net).
37 38
 -   SSH configuration preventing root login and insecure password authentication
@@ -114,6 +115,7 @@ Create `A` or `CNAME` records which point to your server's IP address:
114 115
 * `mail.example.com`
115 116
 * `www.example.com` (for Web hosting)
116 117
 * `autoconfig.example.com` (for email client automatic configuration)
118
+* `fathom.example.com` (for web stats)
117 119
 * `news.example.com` (for Selfoss)
118 120
 * `cloud.example.com` (for ownCloud)
119 121
 

+ 18
- 0
roles/blog/defaults/main.yml Näytä tiedosto

@@ -0,0 +1,18 @@
1
+# pass
2
+secret_root: '{{ inventory_dir | realpath }}'
3
+secret_name: 'secret'
4
+secret: '{{ secret_root + "/" + secret_name }}'
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) }}"
9
+
10
+fathom_db_username: 'fathom'
11
+fathom_db_password: "{{ lookup('password', secret + '/' + 'fathom_db_password', length=32) }}"
12
+fathom_db_database: 'fathom'
13
+fathom_admin_username: "{{ admin_email }}"
14
+fathom_admin_password: "{{ lookup('password', secret + '/' + 'fathom_admin_password', length=32) }}"
15
+fathom_internal_port: '9000'
16
+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"

+ 1
- 1
roles/blog/tasks/blog.yml Näytä tiedosto

@@ -2,7 +2,7 @@
2 2
   file: state=directory path={{ item }} group=www-data owner={{ main_user_name }}
3 3
   with_items: "{{ virtual_domains | json_query('[*].doc_root') | unique }}"
4 4
 
5
-- name: Create the Apache sites config file
5
+- name: Create the Apache sites config files
6 6
   template:
7 7
     src=etc_apache2_sites-available_blog.j2
8 8
     dest=/etc/apache2/sites-available/{{ item.name }}.conf

+ 97
- 0
roles/blog/tasks/fathom.yml Näytä tiedosto

@@ -0,0 +1,97 @@
1
+- name: Create temporary fathom directory
2
+  file: state=directory path=/root/fathom
3
+
4
+- name: Download fathom {{ fathom_version }} release
5
+  get_url:
6
+    url="{{ fathom_release }}"
7
+    dest=/root/fathom/fathom-{{ fathom_version }}.tar.gz
8
+
9
+- name: Decompress fathom release
10
+  unarchive: src=/root/fathom/fathom-{{ fathom_version }}.tar.gz
11
+             dest=/root/fathom copy=no
12
+             creates=/root/fathom/fathom
13
+
14
+- name: Create /usr/local/bin
15
+  file: state=directory path=/usr/local/bin
16
+
17
+- name: Stop old fathom instance
18
+  service: name=fathom-stats state=stopped
19
+
20
+- name: Copy fathom binary to /usr/local/bin
21
+  shell: cp fathom/fathom /usr/local/bin/fathom chdir=/root
22
+
23
+- name: Remove downloaded temporary fathom files
24
+  file: state=absent path=/root/fathom
25
+
26
+- name: Create fathom working directory
27
+  file: state=directory path=/home/{{ main_user_name }}/fathom-stats
28
+
29
+- name: Create fathom config file
30
+  template:
31
+    src=home_user_fathom-stats_env.j2
32
+    dest=/home/{{ main_user_name }}/fathom-stats/.env
33
+    owner={{ main_user_name }}
34
+    group=root
35
+
36
+- name: Add fathom postgres user
37
+  postgresql_user:
38
+    login_host=localhost
39
+    login_user={{ db_admin_username }}
40
+    login_password="{{ db_admin_password }}"
41
+    name={{ fathom_db_username }}
42
+    password="{{ fathom_db_password }}"
43
+    encrypted=yes
44
+    state=present
45
+
46
+- name: Create fathom database
47
+  postgresql_db:
48
+    login_host=localhost
49
+    login_user={{ db_admin_username }}
50
+    login_password="{{ db_admin_password }}"
51
+    name={{ fathom_db_database }}
52
+    state=present
53
+    owner={{ fathom_db_username }}
54
+
55
+- name: Delete old fathom admin user account
56
+  become: true
57
+  become_user: "{{ main_user_name }}"
58
+  shell: fathom user delete --email="{{ fathom_admin_username }}"
59
+  args:
60
+    chdir: /home/{{ main_user_name }}/fathom-stats
61
+
62
+- name: Create fathom admin user account
63
+  become: true
64
+  become_user: "{{ main_user_name }}"
65
+  shell: fathom user add --email="{{ fathom_admin_username }}" --password="{{ fathom_admin_password }}"
66
+  args:
67
+    chdir: /home/{{ main_user_name }}/fathom-stats
68
+
69
+- name: Add systemd service to start fathom automatically
70
+  template:
71
+    src=etc_systemd_system_fathom-stats.j2
72
+    dest=/etc/systemd/system/fathom-stats.service
73
+    owner=root
74
+    group=root
75
+
76
+- name: Register new fathom service
77
+  systemd: name=fathom-stats daemon_reload=yes enabled=yes
78
+
79
+- name: Start new fathom instance
80
+  service: name=fathom-stats state=started
81
+
82
+- name: Create the Apache Fathom sites config files
83
+  template:
84
+    src=etc_apache2_sites-available_fathom.j2
85
+    dest=/etc/apache2/sites-available/fathom_{{ item.name }}.conf
86
+    owner=root
87
+    group=root
88
+  with_items: "{{ virtual_domains }}"
89
+
90
+- name: Remove old sites-enabled symlinks (new ones will be created by a2ensite)
91
+  file: path=/etc/apache2/sites-enabled/fathom_{{ item }}.conf state=absent
92
+  with_items: "{{ virtual_domains | json_query('[*].name') }}"
93
+
94
+- name: Enable Apache sites (creates new sites-enabled symlinks)
95
+  command: a2ensite fathom_{{ item }}.conf creates=/etc/apache2/sites-enabled/fathom_{{ item }}.conf
96
+  notify: restart apache
97
+  with_items: "{{ virtual_domains | json_query('[*].name') }}"

+ 2
- 1
roles/blog/tasks/main.yml Näytä tiedosto

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

+ 20
- 0
roles/blog/templates/etc_apache2_sites-available_fathom.j2 Näytä tiedosto

@@ -0,0 +1,20 @@
1
+<VirtualHost *:80>
2
+    ServerName fathom.{{ item.name }}
3
+
4
+    Redirect permanent / https://{{ item.name }}/
5
+</VirtualHost>
6
+
7
+<VirtualHost *:443>
8
+    ServerName fathom.{{ 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:{{ fathom_internal_port }}/
19
+    ProxyPassReverse        / http://localhost:{{ fathom_internal_port }}/
20
+</VirtualHost>

+ 15
- 0
roles/blog/templates/etc_systemd_system_fathom-stats.j2 Näytä tiedosto

@@ -0,0 +1,15 @@
1
+[Unit]
2
+Description=Starts the fathom server
3
+Requires=network.target
4
+After=network.target
5
+
6
+[Service]
7
+Type=simple
8
+User={{ main_user_name }}
9
+Restart=always
10
+RestartSec=3
11
+WorkingDirectory=/home/{{ main_user_name }}/fathom-stats
12
+ExecStart=/usr/local/bin/fathom server
13
+
14
+[Install]
15
+WantedBy=multi-user.target

+ 10
- 0
roles/blog/templates/home_user_fathom-stats_env.j2 Näytä tiedosto

@@ -0,0 +1,10 @@
1
+FATHOM_SERVER_ADDR={{ fathom_internal_port }}
2
+FATHOM_GZIP=true
3
+FATHOM_DEBUG=false
4
+FATHOM_DATABASE_DRIVER="postgres"
5
+FATHOM_DATABASE_SSLMODE="require"
6
+FATHOM_DATABASE_NAME="{{ fathom_db_database }}"
7
+FATHOM_DATABASE_USER="{{ fathom_db_username }}"
8
+FATHOM_DATABASE_PASSWORD="{{ fathom_db_password }}"
9
+FATHOM_DATABASE_HOST="localhost"
10
+FATHOM_SECRET="{{ fathom_secret }}"

+ 1
- 1
roles/common/files/letsencrypt-gencert Näytä tiedosto

@@ -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 news cloud git; do
20
+  for sub in www mail autoconfig fathom news cloud git; 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/common/tasks/apache.yml Näytä tiedosto

@@ -9,6 +9,14 @@
9 9
   command: a2enmod headers creates=/etc/apache2/mods-enabled/headers.load
10 10
   notify: restart apache
11 11
 
12
+- name: Enable Apache proxy module
13
+  command: a2enmod proxy creates=/etc/apache2/mods-enabled/proxy.load
14
+  notify: restart apache
15
+
16
+- name: Enable Apache proxy http module
17
+  command: a2enmod proxy_http creates=/etc/apache2/mods-enabled/proxy_http.load
18
+  notify: restart apache
19
+
12 20
 - name: Create ServerName configuration file for Apache
13 21
   template: src=fqdn.j2 dest=/etc/apache2/conf-available/fqdn.conf
14 22
 

Loading…
Peruuta
Tallenna