forked from darold/pgcluu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.PL
278 lines (246 loc) · 9.19 KB
/
Makefile.PL
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
use strict;
my @ALLOWED_ARGS = ('INSTALLDIRS','DESTDIR','PREFIX','RSCDIR','REPORTDIR','CGIDIR','CONFDIR','PIDDIR','STATDIR','APACHECONF','MANDIR','DOCDIR','SYSTEMDDIR','RETENTION', 'BINDIR');
# Parse command line arguments and store them as environment variables
while ($_ = shift) {
my ($k,$v) = split(/=/, $_, 2);
if (grep(/^$k$/, @ALLOWED_ARGS)) {
$ENV{$k} = $v;
}
}
$ENV{DESTDIR} =~ s/\/$//;
# Perform some checks
if (exists $ENV{INSTALLDIRS} && $ENV{INSTALLDIRS} !~ /^(site|vendor)$/) {
die "ERROR: INSTALLDIRS value must be 'site' or 'vendor'.\n";
}
# Default install path
my $DESTDIR = $ENV{DESTDIR} || '';
my $PREFIX = $ENV{PREFIX} || '/usr/local';
my $INSTALLDIRS = $ENV{INSTALLDIRS} || 'site';
my $CONFDIR = $ENV{CONFDIR} || "$DESTDIR$PREFIX/etc";
my $CONFDIR_SRVC = $ENV{CONFDIR} || "$PREFIX/etc";
if ($INSTALLDIRS eq 'vendor') {
$PREFIX = $ENV{PREFIX} || '/usr';
$CONFDIR = $ENV{CONFDIR} || "$DESTDIR/etc";
$CONFDIR_SRVC = $ENV{CONFDIR} || "/etc";
}
my $BINDIR = $ENV{BINDIR} || "$DESTDIR$PREFIX/bin";
my $PIDDIR = $ENV{PIDDIR} || "$DESTDIR/var/run/postgresql";
my $STATDIR = $ENV{STATDIR} || "$DESTDIR/var/lib/pgcluu/data";
my $REPORTDIR = $ENV{REPORTDIR} || "$DESTDIR/var/lib/pgcluu/report";
my $RSCDIR = $ENV{RSCDIR} || "$DESTDIR$PREFIX/share/pgcluu";
my $CGIDIR = $ENV{CGIDIR} || "$DESTDIR$PREFIX/lib/cgi-bin";
my $APACHECONF = $ENV{APACHECONF} || "$CONFDIR/apache2/conf-available";
my $MANDIR = $ENV{MANDIR} || "$DESTDIR$PREFIX/share/man";
my $DOCDIR = $ENV{DOCDIR} || "$DESTDIR$PREFIX/share/doc";
my $SYSTEMDDIR = $ENV{SYSTEMDDIR} || "$DESTDIR/lib/systemd/system";
my $RETENTION = $ENV{RETENTION} || 30;
my $STATDIR_SRVC = $ENV{STATDIR} || "/var/lib/pgcluu/data";
my $REPORTDIR_SRVC = $ENV{REPORTDIR} || "/var/lib/pgcluu/report";
my $PIDDIR_SRVC = $ENV{PIDDIR} || "/var/run/postgresql";
my $BINDIR_SRVC = $ENV{BINDIR} || "$PREFIX/bin";
# Try to detect RPM specific directory installation
my $RPM_LIKE = 0;
if ($SYSTEMDDIR eq '/usr/lib/systemd/system' && ! -d '/usr/lib/systemd/system') {
$SYSTEMDDIR = $ENV{SYSTEMDDIR} || '/lib/systemd/system';
}
# Setup ok. generating sendmailanalyzer.conf config file
unless(open(OUTCFG, ">pgcluu.conf")) {
print "\nError: can't write config file pgcluu.conf, $!\n";
exit 0;
}
print OUTCFG qq{
#-----------------------------------------------------------------------------
# Configuration file for pgCluu scripts. Most of the directives are used by
# the CGI script execpt those starting by STATS_COLLECTD_ or STATS_REPORT_
#-----------------------------------------------------------------------------
# Defined the base URL where resources files are stored
# Resources files are css and javascript files.
# Default is to automatically set the relative path.
RSC_BASE /pgcluu/rsc/
# Path to the main pgCluu data directory. This path
# must be readable by the user running your httpd server.
INPUT_DIR $STATDIR_SRVC
# Space or comma separated list of database that must be reported.
# Value can be any valid perl regexp
#INCLUDE_DB [^p].*
# Space or comma separated list of table that must be reported.
# Value can be any valid perl regexp
#INCLUDE_TB tmp.*
# Space or comma separated list of network device that must be reported.
# Value can be any valid perl regexp
#INCLUDE_IFACE lo
# Space or comma separated list of disk device that must be reported.
# Value can be any valid perl regexp
#INCLUDE_DEV sda
# By default pgcluu look at mm/dd/yy format in header line of sar file.
# When enabled pgcluu will look at dd/mm/yy format.
REVERT_DATE 0
# Max number of days in a graph. Using default pgcluu_collectd 1 minute
# interval each, daily graph will have 1440 points. Having too much data
# to render is not a good point for performances with the current code.
# The user can set is own graph period, we are limit it to the first seven
# days of the selected period. This mean a maximum of 10080 points for one
# week, this seems a safe limit. Feel free to increase or reduce the limit
# following the server and client resources.
MAX_RENDERED_DAYS 7
# Retention limit in the statistics directory expressed in number of days.
# This directive is only used by pgcluu_collectd in incremental mode. Only
# the last number of days will be preserved, obsolete directories will be
# removed. It can be used to preserved disk space. Default store 30 days.
STATS_COLLECTD_RETENTION $RETENTION
# Retention limit in the report directory (static html) expressed in number
# of days. This directive is only used by pgcluu in incremental mode. Only
# the last number of days will be preserved, obsolete directories will be
# removed. It can be used to preserved disk space. Default store 30 days.
STATS_REPORT_RETENTION $RETENTION
# This directive must be enabled in CGI mode. In this case pgcluu must be
# run periodically at least each 5 minutes to build and update cached stats.
STATS_REPORT_CACHING 0
# Directory where the pgCluu reports must be saved
STATS_REPORT_OUTDIR $REPORTDIR_SRVC
};
close(OUTCFG);
unless(open(INST, ">install_all.sh")) {
print "\nError: can't write post install file install_all.sh, $!\n";
exit 0;
}
print INST qq{#!/bin/sh
if [ ! -d "$DESTDIR/bin" ]; then
mkdir -p $DESTDIR/bin
fi
if [ ! -d "$CONFDIR" ]; then
mkdir -p $CONFDIR
fi
if [ ! -d "$RSCDIR/rsc" ]; then
mkdir -p $RSCDIR/rsc
fi
if [ ! -d "$MANDIR/man1" ]; then
mkdir -p $MANDIR/man1
fi
if [ ! -d "$DOCDIR/pgcluu" ]; then
mkdir -p $DOCDIR/pgcluu
fi
if [ ! -d "$DOCDIR/pgcluu/examples" ]; then
mkdir -p $DOCDIR/pgcluu/examples
fi
if [ ! -d "$CGIDIR" ]; then
mkdir -p $CGIDIR
fi
if [ ! -d "$APACHECONF" ]; then
mkdir -p $APACHECONF
fi
if [ ! -d "$SYSTEMDDIR" ]; then
mkdir -p $SYSTEMDDIR
fi
if [ ! -d "$STATDIR" ]; then
mkdir -p $STATDIR
chown postgres: $STATDIR
fi
if [ ! -d "$REPORTDIR" ]; then
mkdir -p $REPORTDIR
chown postgres: $REPORTDIR
fi
if [ ! -d "$PIDDIR" ]; then
mkdir -p $PIDDIR
chown postgres: $PIDDIR
fi
# Do not override existing Apache configuration file
if [ ! -f "$APACHECONF/pgcluu.conf" ]; then
echo "
Alias /pgcluu $RSCDIR/
<Directory $RSCDIR/>
Options FollowSymLinks MultiViews
AllowOverride None
Require local
#Require ip 192.1.168.0/24
</Directory>" > $APACHECONF/pgcluu.conf
fi
install -m 755 pgcluu_collectd $DESTDIR/bin/
install -m 755 pgcluu $DESTDIR/bin/
install -m 755 cgi-bin/pgcluu.cgi $CGIDIR/
install -m 644 cgi-bin/rsc/* $RSCDIR/rsc/
install -m 644 LICENSE $DOCDIR/pgcluu/
install -m 644 README $DOCDIR/pgcluu/
install -m 644 ChangeLog $DOCDIR/pgcluu/changelog
install -m 644 pgcluu_collectd.service $DOCDIR/pgcluu/examples/
install -m 644 pgcluu.service $DOCDIR/pgcluu/examples/
install -m 644 pgcluu.timer $DOCDIR/pgcluu/examples/
install -m 644 pgcluu.conf $DOCDIR/pgcluu/examples/pgcluu.conf.dist
# Do not override existing configuration file
if [ ! -f "$CONFDIR/pgcluu.conf" ]; then
install -m 644 pgcluu.conf $CONFDIR/pgcluu.conf
fi
gzip -f $DOCDIR/pgcluu/changelog
if [ ! -e "$MANDIR/man1/pgcluu.1p.gz" ]; then
gzip -f $MANDIR/man1/pgcluu.1p
fi
install -m 644 pgcluu_collectd.service $SYSTEMDDIR/
install -m 644 pgcluu.service $SYSTEMDDIR/
install -m 644 pgcluu.timer $SYSTEMDDIR/
if [ ! -e "/etc/apache2/conf-enabled/pgcluu.conf" ]; then
cd /etc/apache2/conf-enabled/
ln -s ../conf-available/pgcluu.conf pgcluu.conf
fi
cd $MANDIR/man1/
ln -s pgcluu.1p.gz pgcluu_collectd.1p.gz
};
close(INST);
`chmod 755 install_all.sh`;
`perl -p -i -e 's#my \\\$CONFIG_FILE .*#my \\\$CONFIG_FILE = "$CONFDIR_SRVC/pgcluu.conf";#' cgi-bin/pgcluu.cgi pgcluu_collectd pgcluu`;
`perl -p -i -e 's#my \\\$PIDFILE .*=.*#my \\\$PIDFILE = "$PIDDIR_SRVC/pgcluu_collectd.pid";#' pgcluu_collectd`;
`perl -p -i -e 's#/var/lib/pgcluu/data#$STATDIR_SRVC#' pgcluu.service pgcluu_collectd.service`;
`perl -p -i -e 's#/var/lib/pgcluu/report#$REPORTDIR_SRVC#' pgcluu.service`;
`perl -p -i -e 's#/usr/bin#$BINDIR_SRVC#' pgcluu.service pgcluu_collectd.service`;
`perl -p -i -e 's#/var/run/postgresql#$PIDDIR_SRVC#' pgcluu_collectd.service`;
my %merge_compat = ();
if ($ExtUtils::MakeMaker::VERSION >= 6.46) {
%merge_compat = (
'META_MERGE' => {
resources => {
homepage => 'http://pgcluu.darold.net/',
repository => {
type => 'git',
git => '[email protected]:darold/pgcluu.git',
web => 'http://pgcluu.darold.net/',
},
},
}
);
}
WriteMakefile(
'DISTNAME' => 'pgcluu',
'NAME' => 'pgCluu',
'VERSION_FROM' => 'pgcluu',
'dist' => {
'COMPRESS'=>'gzip -9f', 'SUFFIX' => 'gz',
'ZIP'=>'/usr/bin/zip','ZIPFLAGS'=>'-rl'
},
'AUTHOR' => 'Gilles Darold ([email protected])',
'ABSTRACT' => 'pgCluu - PostgreSQL performances auditing tool',
'EXE_FILES' => [ qw(pgcluu pgcluu_collectd) ],
'MAN1PODS' => { 'doc/pgCluu.pod' => 'blib/man1/pgcluu.1p' },
'DESTDIR' => $ENV{DESTDIR},
'INSTALLDIRS' => $ENV{INSTALLDIRS},
'clean' => {FILES => "install_all.sh"},
%merge_compat
);
sub MY::install {
my $self = shift;
my $string = $self->MM::install;
$string =~ s/(pure_install\s+)(.*)/$1 install_all $2/;
return $string;
}
sub MY::postamble {
my $postamble = <<'END';
install_all: install_all.sh
sh install_all.sh
END
return $postamble;
}
if (!$ENV{QUIET}) {
print "Done...\n\n";
print "Now type 'make && make install'\n\n";
}