-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rezeptfile
152 lines (126 loc) · 2.77 KB
/
Rezeptfile
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# vi: ft=ruby
# require 'yaml' # You can also use toml, jsonnet, or whatever you want.
# This file is not in the repository, but already on the machine.
# secrets = YAML.load_file "/etc/secrets.yaml"
# password = secrets["postfix"]["password"]
# Generic
group "people" do
gid 887
end
user "marius" do
uid 887
gid 887
system_user true
home "/nonexistent"
shell "/usr/sbin/nologin"
end
package "xz-utils"
if ubuntu?
delete do
snap_package "lxd"
end
end
# Backups
if debian?
package "restic"
else
snap_package "restic"
end
file "/etc/resticenv" do
mode "0700"
contents <<~EOT
export RESTIC_PASSWORD=test123
export RESTIC_REPOSITORY=/restic-repo
export RESTIC_CACHE_DIR=/var/cache/restic
EOT
end
directory "/restic-repo" do
on_change "echo Restic repository created."
end
unless File.exist? "/restic-repo/config"
run ". /etc/resticenv; restic init --repo /restic-repo"
end
file "/etc/backup_exclude" do
contents <<~EOT
/boot/*
/dev/*
/home/*/.bash_history
/home/*/.cache/*
/home/*/.local/share/Trash
/home/*/.mozilla/firefox/*/Cache
/lib/modules/*/volatile/.mounted
/media/*
/mnt/*
/proc/*
/restic-repo
/run/*
/tmp/*
/usr/lib/firmware/*
/usr/lib/modules/*
/snap/*
/swap.img
/sys/*
/vagrant/*
/var/cache/*
/var/lib/snapd/snaps/*
/var/lock/*
/var/run/*
/var/tmp/*
/var/lib/lxcfs/*
EOT
end
file "/usr/libexec/backup" do
mode "0700"
contents <<~EOT
#!/bin/bash
set -Eeuxo pipefail
source /etc/resticenv
export RESTIC_PROGRESS_FPS=0.05
PARAMS='--limit-download=4000 --limit-upload=4000 --verbose'
# Stupid cat hack is needed for stdout to show up in the systemd journal
restic $PARAMS backup / --exclude-file=/etc/backup_exclude 2>&1 | cat
restic $PARAMS forget --prune --keep-daily=7 --keep-weekly=5 --keep-monthly=6 2>&1 | cat
EOT
end
systemd_timer_service "backup" do
timer "OnCalendar=07:37"
contents <<~EOT
[Unit]
Description=Backup this machine
[Service]
Type=oneshot
ExecStart=/usr/libexec/backup
EOT
end
# Webserver
package "nginx"
delete do
file "/etc/nginx/sites-enabled/default" do
reload "nginx"
end
end
directory "/var/www/example.com"
file "/etc/nginx/sites-enabled/example.com" do
contents File.read("example.com")
reload "nginx"
on_change "echo Some other stuff could happen here"
end
# A Systemd service
systemd_service "helloer" do
contents <<~EOT
[Unit]
Description=Unit description
[Service]
Type=oneshot
ExecStart=/usr/bin/echo Hello
[Install]
WantedBy=multi-user.target
EOT
end
run "echo Top of the morning to you!"
unless Dir.exist? "/etc/letsencrypt/live/example.com"
run "echo certbot ..."
end
swapfile "/swapfile" do
size "2G"
end