-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvarnish.postinst
76 lines (61 loc) · 1.86 KB
/
varnish.postinst
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
#!/bin/sh
# Postinst script for varnish.
# Stig Sandbeck Mathisen <[email protected]>
set -e
set -u
# Settings
daemon_user="varnish"
log_user="varnishlog"
daemon_dir=/var/lib/varnish/$(uname -n)
log_dir="/var/log/varnish"
secret_file=/etc/varnish/secret
varnish_setup_user() {
if ! getent passwd $1 2>&1 >/dev/null; then
adduser --quiet --system --no-create-home --group $1
fi
}
varnish_create_storagedir() {
if ! [ -d "$daemon_dir" ]; then
install -o $daemon_user -g $daemon_user -d $daemon_dir
fi
}
varnish_setup_logdir() {
if ! dpkg-statoverride --list $log_dir >/dev/null; then
dpkg-statoverride --update --add $log_user $log_user 0750 $log_dir
fi
}
varnish_create_secret() {
if ! [ -f "${secret_file}" ]; then
if [ -f /proc/sys/kernel/random/uuid ]; then
install -m 0600 /proc/sys/kernel/random/uuid "${secret_file}"
else
install -m 0600 /dev/null "${secret_file}"
dd if=/dev/urandom count=1 bs=128 2>/dev/null \
| tr -dc "A-Za-z0-9" > "${secret_file}"
fi
fi
}
# varnish version 2.1.3-1 and older ran the log demons as root, we
# need to change the owner of the old logs for upgrading clients
upgrade_change_log_permissions() {
chown -Rhf ${log_user}: ${log_dir}
}
# varnish version 2.1.3-1 and older started varnishd at boot, we keep
# this default for upgrading clients
upgrade_enable_varnishd() {
sed -i '/^START=/s/no/yes/g' /etc/default/varnish
}
case ${1:-} in
configure)
varnish_setup_user $daemon_user
varnish_setup_user $log_user
varnish_create_storagedir
varnish_setup_logdir
varnish_create_secret
if dpkg --compare-versions "2.1.3-2" "gt-nl" "${2:-}" ; then
upgrade_change_log_permissions
upgrade_enable_varnishd
fi
;;
esac
#DEBHELPER#