tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
graylog service: Initial graylog service
Tristan Helmich
9 years ago
e48580c0
49b94763
+163
3 changed files
expand all
collapse all
unified
split
nixos
modules
misc
ids.nix
module-list.nix
services
logging
graylog.nix
+1
nixos/modules/misc/ids.nix
···
264
264
taskd = 240;
265
265
factorio = 241;
266
266
emby = 242;
267
267
+
graylog = 243;
267
268
268
269
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
269
270
+1
nixos/modules/module-list.nix
···
183
183
./services/hardware/thermald.nix
184
184
./services/logging/awstats.nix
185
185
./services/logging/fluentd.nix
186
186
+
./services/logging/graylog.nix
186
187
./services/logging/klogd.nix
187
188
./services/logging/logcheck.nix
188
189
./services/logging/logrotate.nix
+161
nixos/modules/services/logging/graylog.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
3
3
+
with lib;
4
4
+
5
5
+
let
6
6
+
cfg = config.services.graylog;
7
7
+
configBool = b: if b then "true" else "false";
8
8
+
9
9
+
confFile = pkgs.writeText "graylog.conf" ''
10
10
+
is_master = ${configBool cfg.isMaster}
11
11
+
node_id_file = ${cfg.nodeIdFile}
12
12
+
password_secret = ${cfg.passwordSecret}
13
13
+
root_username = ${cfg.rootUsername}
14
14
+
root_password_sha2 = ${cfg.rootPasswordSha2}
15
15
+
elasticsearch_cluster_name = ${cfg.elasticsearchClusterName}
16
16
+
elasticsearch_discovery_zen_ping_multicast_enabled = ${configBool cfg.elasticsearchDiscoveryZenPingMulticastEnabled}
17
17
+
elasticsearch_discovery_zen_ping_unicast_hosts = ${cfg.elasticsearchDiscoveryZenPingUnicastHosts}
18
18
+
message_journal_dir = ${cfg.messageJournalDir}
19
19
+
mongodb_uri = ${cfg.mongodbUri}
20
20
+
21
21
+
${cfg.extraConfig}
22
22
+
'';
23
23
+
in
24
24
+
25
25
+
{
26
26
+
###### interface
27
27
+
28
28
+
options = {
29
29
+
30
30
+
services.graylog = {
31
31
+
32
32
+
enable = mkEnableOption "Graylog";
33
33
+
34
34
+
package = mkOption {
35
35
+
type = types.package;
36
36
+
default = pkgs.graylog;
37
37
+
defaultText = "pkgs.graylog";
38
38
+
example = literalExample "pkgs.graylog";
39
39
+
description = "Graylog package to use.";
40
40
+
};
41
41
+
42
42
+
user = mkOption {
43
43
+
type = types.str;
44
44
+
default = "graylog";
45
45
+
example = literalExample "graylog";
46
46
+
description = "User account under which graylog runs";
47
47
+
};
48
48
+
49
49
+
isMaster = mkOption {
50
50
+
type = types.bool;
51
51
+
default = true;
52
52
+
description = "Whether this is the master instance of your Graylog cluster";
53
53
+
};
54
54
+
55
55
+
nodeIdFile = mkOption {
56
56
+
type = types.str;
57
57
+
default = "/var/lib/graylog/server/node-id";
58
58
+
description = "Path of the file containing the graylog node-id";
59
59
+
};
60
60
+
61
61
+
passwordSecret = mkOption {
62
62
+
type = types.str;
63
63
+
description = ''
64
64
+
You MUST set a secret to secure/pepper the stored user passwords here. Use at least 64 characters.
65
65
+
Generate one by using for example: pwgen -N 1 -s 96
66
66
+
'';
67
67
+
};
68
68
+
69
69
+
rootUsername = mkOption {
70
70
+
type = types.str;
71
71
+
default = "admin";
72
72
+
description = "Name of the default administrator user";
73
73
+
};
74
74
+
75
75
+
rootPasswordSha2 = mkOption {
76
76
+
type = types.str;
77
77
+
example = "e3c652f0ba0b4801205814f8b6bc49672c4c74e25b497770bb89b22cdeb4e952";
78
78
+
description = ''
79
79
+
You MUST specify a hash password for the root user (which you only need to initially set up the
80
80
+
system and in case you lose connectivity to your authentication backend)
81
81
+
This password cannot be changed using the API or via the web interface. If you need to change it,
82
82
+
modify it here.
83
83
+
Create one by using for example: echo -n yourpassword | shasum -a 256
84
84
+
and use the resulting hash value as string for the option
85
85
+
'';
86
86
+
};
87
87
+
88
88
+
elasticsearchClusterName = mkOption {
89
89
+
type = types.str;
90
90
+
example = "graylog";
91
91
+
description = "This must be the same as for your Elasticsearch cluster";
92
92
+
};
93
93
+
94
94
+
elasticsearchDiscoveryZenPingMulticastEnabled = mkOption {
95
95
+
type = types.bool;
96
96
+
default = false;
97
97
+
description = "Whether to use elasticsearch multicast discovery";
98
98
+
};
99
99
+
100
100
+
elasticsearchDiscoveryZenPingUnicastHosts = mkOption {
101
101
+
type = types.str;
102
102
+
default = "127.0.0.1:9300";
103
103
+
description = "Tells Graylogs Elasticsearch client how to find other cluster members. See Elasticsearch documentation for details";
104
104
+
};
105
105
+
106
106
+
messageJournalDir = mkOption {
107
107
+
type = types.str;
108
108
+
default = "/var/lib/graylog/data/journal";
109
109
+
description = "The directory which will be used to store the message journal. The directory must be exclusively used by Graylog and must not contain any other files than the ones created by Graylog itself";
110
110
+
};
111
111
+
112
112
+
mongodbUri = mkOption {
113
113
+
type = types.str;
114
114
+
default = "mongodb://localhost/graylog";
115
115
+
description = "MongoDB connection string. See http://docs.mongodb.org/manual/reference/connection-string/ for details";
116
116
+
};
117
117
+
118
118
+
extraConfig = mkOption {
119
119
+
type = types.str;
120
120
+
default = "";
121
121
+
description = "Any other configuration options you might want to add";
122
122
+
};
123
123
+
124
124
+
};
125
125
+
};
126
126
+
127
127
+
128
128
+
###### implementation
129
129
+
130
130
+
config = mkIf cfg.enable {
131
131
+
132
132
+
users.extraUsers = mkIf (cfg.user == "graylog") {
133
133
+
graylog = {
134
134
+
uid = config.ids.uids.graylog;
135
135
+
description = "Graylog server daemon user";
136
136
+
};
137
137
+
};
138
138
+
139
139
+
systemd.services.graylog = with pkgs; {
140
140
+
description = "Graylog Server";
141
141
+
wantedBy = [ "multi-user.target" ];
142
142
+
environment = {
143
143
+
JAVA_HOME = jre;
144
144
+
GRAYLOG_CONF = "${confFile}";
145
145
+
};
146
146
+
path = [ pkgs.openjdk8 pkgs.which pkgs.procps ];
147
147
+
preStart = ''
148
148
+
mkdir -p /var/lib/graylog -m 755
149
149
+
chown -R ${cfg.user} /var/lib/graylog
150
150
+
151
151
+
mkdir -p ${cfg.messageJournalDir} -m 755
152
152
+
chown -R ${cfg.user} ${cfg.messageJournalDir}
153
153
+
'';
154
154
+
serviceConfig = {
155
155
+
User="${cfg.user}";
156
156
+
PermissionsStartOnly=true;
157
157
+
ExecStart = "${cfg.package}/bin/graylogctl run";
158
158
+
};
159
159
+
};
160
160
+
};
161
161
+
}