tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
awstats: init at 7.4, including a simple service
Vladimír Čunát
10 years ago
6f9fe31b
85001098
+184
4 changed files
expand all
collapse all
unified
split
nixos
modules
module-list.nix
services
logging
awstats.nix
pkgs
tools
system
awstats
default.nix
top-level
all-packages.nix
+1
nixos/modules/module-list.nix
···
176
176
./services/hardware/udisks2.nix
177
177
./services/hardware/upower.nix
178
178
./services/hardware/thermald.nix
179
179
+
./services/logging/awstats.nix
179
180
./services/logging/fluentd.nix
180
181
./services/logging/klogd.nix
181
182
./services/logging/logcheck.nix
+123
nixos/modules/services/logging/awstats.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
3
3
+
with lib;
4
4
+
5
5
+
let
6
6
+
cfg = config.services.awstats;
7
7
+
package = pkgs.awstats;
8
8
+
in
9
9
+
10
10
+
{
11
11
+
options.services.awstats = {
12
12
+
enable = mkOption {
13
13
+
type = types.bool;
14
14
+
default = cfg.service.enable;
15
15
+
description = ''
16
16
+
Enable the awstats program (but not service).
17
17
+
Currently only simple httpd (Apache) configs are supported,
18
18
+
and awstats plugins may not work correctly.
19
19
+
'';
20
20
+
};
21
21
+
vardir = mkOption {
22
22
+
type = types.path;
23
23
+
default = "/var/lib/awstats";
24
24
+
description = "The directory where variable awstats data will be stored.";
25
25
+
};
26
26
+
27
27
+
extraConfig = mkOption {
28
28
+
type = types.lines;
29
29
+
default = "";
30
30
+
description = "Extra configuration to be appendend to awstats.conf.";
31
31
+
};
32
32
+
33
33
+
updateAt = mkOption {
34
34
+
type = types.nullOr types.string;
35
35
+
default = null;
36
36
+
example = "hourly";
37
37
+
description = ''
38
38
+
Specification of the time at which awstats will get updated.
39
39
+
(in the format described by <citerefentry>
40
40
+
<refentrytitle>systemd.time</refentrytitle>
41
41
+
<manvolnum>5</manvolnum></citerefentry>)
42
42
+
'';
43
43
+
};
44
44
+
45
45
+
service = {
46
46
+
enable = mkOption {
47
47
+
type = types.bool;
48
48
+
default = false;
49
49
+
description = ''Enable the awstats web service. This switches on httpd.'';
50
50
+
};
51
51
+
urlPrefix = mkOption {
52
52
+
type = types.string;
53
53
+
default = "/awstats";
54
54
+
description = "The URL prefix under which the awstats service appears.";
55
55
+
};
56
56
+
};
57
57
+
};
58
58
+
59
59
+
60
60
+
config = mkIf cfg.enable {
61
61
+
environment.systemPackages = [ package.bin ];
62
62
+
/* TODO:
63
63
+
- heed config.services.httpd.logPerVirtualHost, etc.
64
64
+
- Can't AllowToUpdateStatsFromBrowser, as CGI scripts don't have permission
65
65
+
to read the logs, and our httpd config apparently doesn't an option for that.
66
66
+
*/
67
67
+
environment.etc."awstats/awstats.conf".source = pkgs.runCommand "awstats.conf"
68
68
+
{ preferLocalBuild = true; }
69
69
+
( let
70
70
+
cfg-httpd = config.services.httpd;
71
71
+
logFormat =
72
72
+
if cfg-httpd.logFormat == "combined" then "1" else
73
73
+
if cfg-httpd.logFormat == "common" then "4" else
74
74
+
throw "awstats service doesn't support Apache log format `${cfg-httpd.logFormat}`";
75
75
+
in
76
76
+
''
77
77
+
sed \
78
78
+
-e 's|^\(DirData\)=.*$|\1="${cfg.vardir}"|' \
79
79
+
-e 's|^\(DirIcons\)=.*$|\1="icons"|' \
80
80
+
-e 's|^\(CreateDirDataIfNotExists\)=.*$|\1=1|' \
81
81
+
-e 's|^\(SiteDomain\)=.*$|\1="${cfg-httpd.hostName}"|' \
82
82
+
-e 's|^\(LogFile\)=.*$|\1="${cfg-httpd.logDir}/access_log"|' \
83
83
+
-e 's|^\(LogFormat\)=.*$|\1=${logFormat}|' \
84
84
+
< '${package.out}/wwwroot/cgi-bin/awstats.model.conf' > "$out"
85
85
+
echo '${cfg.extraConfig}' >> "$out"
86
86
+
'');
87
87
+
88
88
+
# The httpd sub-service showing awstats.
89
89
+
services.httpd.enable = mkIf cfg.service.enable true;
90
90
+
services.httpd.extraSubservices = mkIf cfg.service.enable [ { function = { serverInfo, ... }: {
91
91
+
extraConfig =
92
92
+
''
93
93
+
Alias ${cfg.service.urlPrefix}/classes "${package.out}/wwwroot/classes/"
94
94
+
Alias ${cfg.service.urlPrefix}/css "${package.out}/wwwroot/css/"
95
95
+
Alias ${cfg.service.urlPrefix}/icons "${package.out}/wwwroot/icon/"
96
96
+
ScriptAlias ${cfg.service.urlPrefix}/ "${package.out}/wwwroot/cgi-bin/"
97
97
+
98
98
+
<Directory "${package.out}/wwwroot">
99
99
+
Options None
100
100
+
AllowOverride None
101
101
+
Order allow,deny
102
102
+
Allow from all
103
103
+
</Directory>
104
104
+
'';
105
105
+
startupScript =
106
106
+
let
107
107
+
inherit (serverInfo.serverConfig) user group;
108
108
+
in pkgs.writeScript "awstats_startup.sh"
109
109
+
''
110
110
+
mkdir -p '${cfg.vardir}'
111
111
+
chown '${user}:${group}' '${cfg.vardir}'
112
112
+
'';
113
113
+
};}];
114
114
+
115
115
+
systemd.services.awstats-update = mkIf (cfg.updateAt != null) {
116
116
+
description = "awstats log collector";
117
117
+
script = "exec '${package.bin}/bin/awstats' -update -config=awstats.conf";
118
118
+
startAt = cfg.updateAt;
119
119
+
};
120
120
+
};
121
121
+
122
122
+
}
123
123
+
+58
pkgs/tools/system/awstats/default.nix
···
1
1
+
{ stdenv, fetchurl, perlPackages, jdk }:
2
2
+
3
3
+
perlPackages.buildPerlPackage rec {
4
4
+
name = "awstats-${version}";
5
5
+
version = "7.4";
6
6
+
7
7
+
src = fetchurl {
8
8
+
url = "mirror://sourceforge/awstats/${name}.tar.gz";
9
9
+
sha256 = "0mdbilsl8g9a84qgyws4pakhqr3mfhs5g5dqbgsn9gn285rzxas3";
10
10
+
};
11
11
+
12
12
+
postPatch = ''
13
13
+
substituteInPlace wwwroot/cgi-bin/awstats.pl \
14
14
+
--replace /usr/share/awstats/ "$out/wwwroot/cgi-bin/"
15
15
+
'';
16
16
+
17
17
+
outputs = [ "out" "bin" "doc" ];
18
18
+
19
19
+
buildInputs = with perlPackages; [ ]; # plugins will need some
20
20
+
21
21
+
preConfigure = ''
22
22
+
touch Makefile.PL
23
23
+
patchShebangs .
24
24
+
'';
25
25
+
26
26
+
# build our own JAR
27
27
+
preBuild = ''
28
28
+
(
29
29
+
cd wwwroot/classes/src
30
30
+
rm ../*.jar
31
31
+
PATH="${jdk}/bin" "$(type -P perl)" Makefile.pl
32
32
+
test -f ../*.jar
33
33
+
)
34
34
+
'';
35
35
+
36
36
+
doCheck = false;
37
37
+
38
38
+
installPhase = ''
39
39
+
mkdir "$out"
40
40
+
mv wwwroot "$out/wwwroot"
41
41
+
rm -r "$out/wwwroot/classes/src/"
42
42
+
43
43
+
mkdir -p "$bin/bin"
44
44
+
ln -s "$out/wwwroot/cgi-bin/awstats.pl" "$bin/bin/awstats"
45
45
+
46
46
+
mkdir -p "$doc/share/"
47
47
+
mv README.md docs/
48
48
+
mv docs "$doc/share/awstats"
49
49
+
'';
50
50
+
51
51
+
meta = with stdenv.lib; {
52
52
+
description = "Real-time logfile analyzer to get advanced statistics";
53
53
+
homepage = http://awstats.org;
54
54
+
license = licenses.gpl3Plus;
55
55
+
platforms = platforms.linux;
56
56
+
};
57
57
+
}
58
58
+
+2
pkgs/top-level/all-packages.nix
···
676
676
677
677
aws_mturk_clt = callPackage ../tools/misc/aws-mturk-clt { };
678
678
679
679
+
awstats = callPackage ../tools/system/awstats { };
680
680
+
679
681
axel = callPackage ../tools/networking/axel { };
680
682
681
683
azureus = callPackage ../tools/networking/p2p/azureus { };