This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
/
tpl_redis.go
124 lines (112 loc) · 2.91 KB
/
tpl_redis.go
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
package main
import (
"github.com/dynport/urknall"
"github.com/dynport/urknall/cmd"
)
type Redis struct {
Version string `urknall:"required=true"` // e.g. 2.8.12
Autostart bool
}
func (redis *Redis) InstallDir() string {
if redis.Version == "" {
panic("Version must be set")
}
return "/opt/redis-" + redis.Version
}
func (redis *Redis) Render(pkg urknall.Package) {
pkg.AddCommands("base",
InstallPackages("build-essential"),
Mkdir("/opt/src/", "root", 0755),
DownloadAndExtract(redis.url(), "/opt/src/"),
And(
"cd /opt/src/redis-{{ .Version }}",
"make",
"PREFIX={{ .InstallDir }} make install",
),
Mkdir("/data/redis", "root", 0755),
)
pkg.AddTemplate("config", &RedisConfig{})
pkg.AddTemplate("upstart", &RedisUpstart{RedisDir: redis.InstallDir(), Autostart: redis.Autostart})
}
func (redis *Redis) WriteConfig(config string) cmd.Command {
return WriteFile("/etc/redis.conf", config, "root", 0644)
}
func (redis *Redis) url() string {
return "http://download.redis.io/releases/redis-{{ .Version }}.tar.gz"
}
type RedisConfig struct {
Port int `urknall:"default=6379"`
Path string `urknall:"default=/etc/redis.conf"`
SyslogIdent string `urknall:"default=redis"`
}
func (redis *RedisConfig) Render(pkg urknall.Package) {
pkg.AddCommands("base",
WriteFile(redis.Path, redisCfg, "root", 0644),
)
}
const redisCfg = `daemonize no
port {{ .Port }}
timeout 0
tcp-keepalive 0
loglevel notice
syslog-enabled yes
syslog-ident {{ .SyslogIdent }}
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
`
type RedisUpstart struct {
Name string `urknall:"default=redis"`
RedisConfig string `urknall:"default=/etc/redis.conf"`
RedisDir string `urknall:"required=true"`
Autostart bool
}
func (u *RedisUpstart) Render(r urknall.Package) {
r.AddCommands("base",
WriteFile("/etc/init/{{ .Name }}.conf", redisUpstart, "root", 0644),
)
return
}
const redisUpstart = `
{{ if .Autostart }}
start on (local-filesystems and net-device-up IFACE!=lo)
{{ end }}
pre-start script
sysctl vm.overcommit_memory=1
end script
exec {{ .RedisDir }}/bin/redis-server {{ .RedisConfig }}
respawn
respawn limit 10 60
`