diff options
author | Leonardo Arena <rnalrd@alpinelinux.org> | 2018-07-25 09:49:12 +0000 |
---|---|---|
committer | Leonardo Arena <rnalrd@alpinelinux.org> | 2018-07-25 09:49:22 +0000 |
commit | bd3340f2e7fa5825da7f313622faef686cda17ab (patch) | |
tree | 9a9300e350e01064d90642145a032e34d2e6d75b /non-free | |
parent | a31b8a8b2a3ab95945396c81089bed44fd89f6f6 (diff) | |
download | alpine_aports-bd3340f2e7fa5825da7f313622faef686cda17ab.tar.bz2 alpine_aports-bd3340f2e7fa5825da7f313622faef686cda17ab.tar.xz alpine_aports-bd3340f2e7fa5825da7f313622faef686cda17ab.zip |
non-free/unifi: add DB cron job
(disabled by default)
Diffstat (limited to 'non-free')
-rw-r--r-- | non-free/unifi/APKBUILD | 12 | ||||
-rw-r--r-- | non-free/unifi/mongo_prune.js | 87 | ||||
-rwxr-xr-x | non-free/unifi/unifi_db_prune.cron | 2 |
3 files changed, 99 insertions, 2 deletions
diff --git a/non-free/unifi/APKBUILD b/non-free/unifi/APKBUILD index 25fab6f580..2664bf5feb 100644 --- a/non-free/unifi/APKBUILD +++ b/non-free/unifi/APKBUILD | |||
@@ -4,7 +4,7 @@ pkgname=unifi | |||
4 | _pkgname=UniFi | 4 | _pkgname=UniFi |
5 | pkgver=5.8.23 | 5 | pkgver=5.8.23 |
6 | _pkgver=d5a5bbfda4 | 6 | _pkgver=d5a5bbfda4 |
7 | pkgrel=0 | 7 | pkgrel=1 |
8 | pkgdesc="The Ubiquiti UniFi network controller" | 8 | pkgdesc="The Ubiquiti UniFi network controller" |
9 | url="http://wiki.ubnt.com/UniFi_FAQ" | 9 | url="http://wiki.ubnt.com/UniFi_FAQ" |
10 | arch="noarch" | 10 | arch="noarch" |
@@ -19,6 +19,8 @@ source="$pkgname-$pkgver.zip::https://dl.ubnt.com/unifi/$pkgver-$_pkgver/$_pkgna | |||
19 | $pkgname.initd | 19 | $pkgname.initd |
20 | $pkgname.confd | 20 | $pkgname.confd |
21 | $pkgname.logrotated | 21 | $pkgname.logrotated |
22 | mongo_prune.js | ||
23 | unifi_db_prune.cron | ||
22 | " | 24 | " |
23 | builddir="$srcdir/$_pkgname" | 25 | builddir="$srcdir/$_pkgname" |
24 | 26 | ||
@@ -79,9 +81,15 @@ package() { | |||
79 | 81 | ||
80 | # tell search engines to do not index | 82 | # tell search engines to do not index |
81 | echo -e "User-Agent:*\nDisallow:/" > "$webapps"/$pkgname/ROOT/robots.txt | 83 | echo -e "User-Agent:*\nDisallow:/" > "$webapps"/$pkgname/ROOT/robots.txt |
84 | |||
85 | # install purging DB job (disabled by default) | ||
86 | install -Dm644 "$srcdir"/mongo_prune.js "$pkgdir"/etc/unifi/mongo_prune.js | ||
87 | install -Dm755 "$srcdir"/unifi_db_prune.cron "$pkgdir"/etc/periodic/weekly/unifi_db_prune | ||
82 | } | 88 | } |
83 | 89 | ||
84 | sha512sums="2b42df2a84574ac9e282c7ff59eb86ce29170ea7ef5957690dec8772c90acda3c08c633b3bceeac08bb73ff1460143207a64d2405de19436faf20a042849231b unifi-5.8.23.zip | 90 | sha512sums="2b42df2a84574ac9e282c7ff59eb86ce29170ea7ef5957690dec8772c90acda3c08c633b3bceeac08bb73ff1460143207a64d2405de19436faf20a042849231b unifi-5.8.23.zip |
85 | b19a7d684ef2ec7c4159417c21185ccd8ce498da25405b69014fdb32e346a0077f7edc5dfc994481d12936aa8dbf22e6baf29571fd0003aaad19609d24c549f4 unifi.initd | 91 | b19a7d684ef2ec7c4159417c21185ccd8ce498da25405b69014fdb32e346a0077f7edc5dfc994481d12936aa8dbf22e6baf29571fd0003aaad19609d24c549f4 unifi.initd |
86 | d339555a91de7488badbedf8a4c85cff878e7d0720a8cf6a8340f51f3666dcf4878b47a1fff4c9c2846d7af140d11e48e898f8c4dba1f81c1004b76a81f0821e unifi.confd | 92 | d339555a91de7488badbedf8a4c85cff878e7d0720a8cf6a8340f51f3666dcf4878b47a1fff4c9c2846d7af140d11e48e898f8c4dba1f81c1004b76a81f0821e unifi.confd |
87 | 9e54d9e1c720b8e50c9af9363105f6ea9ff2cffff7dc67477a7701aacf21ba977424fe9fbaba6a00d5f64310a2e2517e9328a7acb91a4bc06ed237139a8e0d9b unifi.logrotated" | 93 | 9e54d9e1c720b8e50c9af9363105f6ea9ff2cffff7dc67477a7701aacf21ba977424fe9fbaba6a00d5f64310a2e2517e9328a7acb91a4bc06ed237139a8e0d9b unifi.logrotated |
94 | 3eec528077af9b32aa065610b4ffc50537a1c851c84624eaa63287787d853c0f8c953a97bd58bc6c2cab7f9f26eaff8c8b2815a84454169f7e0d96b94dfc91ee mongo_prune.js | ||
95 | 25d66b144403676bcb6142f4942b62c6f969a6b359ccb4dd4fcb826b1e57f902179d01182369704970b2d6094b8b3789fd375c17cec908cac53f7abf01fb2e1b unifi_db_prune.cron" | ||
diff --git a/non-free/unifi/mongo_prune.js b/non-free/unifi/mongo_prune.js new file mode 100644 index 0000000000..421c3f1438 --- /dev/null +++ b/non-free/unifi/mongo_prune.js | |||
@@ -0,0 +1,87 @@ | |||
1 | // keep N-day worth of data | ||
2 | var days=14; | ||
3 | |||
4 | // change to false to have the script to really exclude old records | ||
5 | // from the database. While true, no change at all will be made to the DB | ||
6 | var dryrun=true; | ||
7 | |||
8 | var now = new Date().getTime(), | ||
9 | time_criteria = now - days * 86400 * 1000, | ||
10 | time_criteria_in_seconds = time_criteria / 1000; | ||
11 | |||
12 | print((dryrun ? "[dryrun] " : "") + "pruning data older than " + days + " days (" + time_criteria + ")... "); | ||
13 | |||
14 | use ace; | ||
15 | var collectionNames = db.getCollectionNames(); | ||
16 | for (i=0; i<collectionNames.length; i++) { | ||
17 | var name = collectionNames[i]; | ||
18 | var query = null; | ||
19 | |||
20 | if (name === 'event' || name === 'alarm') { | ||
21 | query = {time: {$lt:time_criteria}}; | ||
22 | } | ||
23 | |||
24 | // rogue ap | ||
25 | if (name === 'rogue') { | ||
26 | query = {last_seen: {$lt:time_criteria_in_seconds}}; | ||
27 | } | ||
28 | |||
29 | // removes vouchers expired more than '$days' ago | ||
30 | // active and unused vouchers are NOT touched | ||
31 | if (name === 'voucher') { | ||
32 | query = {end_time: {$lt:time_criteria_in_seconds}}; | ||
33 | } | ||
34 | |||
35 | // guest authorization | ||
36 | if (name === 'guest') { | ||
37 | query = {end: {$lt:time_criteria_in_seconds}}; | ||
38 | } | ||
39 | |||
40 | // if an user was only seen ONCE, $last_seen will not be defined | ||
41 | // so, if $last_seen not defined, lets use $first_seen instead | ||
42 | // also check if $blocked or $use_fixedip is set. If true, do NOT purge the | ||
43 | // entry no matter how old it is. We want blocked/fixed_ip users to continue | ||
44 | // blocked/fixed_ip | ||
45 | if (name === 'user') { | ||
46 | query = { blocked: { $ne: true}, use_fixedip: { $ne: true}, $or: [ | ||
47 | {last_seen: {$lt:time_criteria_in_seconds} }, | ||
48 | {last_seen: {$exists: false}, first_seen: {$lt:time_criteria_in_seconds} } | ||
49 | ] | ||
50 | }; | ||
51 | } | ||
52 | |||
53 | if (query) { | ||
54 | count1 = db.getCollection(name).count(); | ||
55 | count2 = db.getCollection(name).find(query).count(); | ||
56 | print((dryrun ? "[dryrun] " : "") + "pruning " + count2 + " entries (total " + count1 + ") from " + name + "... "); | ||
57 | if (!dryrun) { | ||
58 | db.getCollection(name).remove(query); | ||
59 | db.runCommand({ compact: name }); | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | |||
64 | use ace_stat; | ||
65 | var collectionNames = db.getCollectionNames(); | ||
66 | for (i=0; i<collectionNames.length; i++) { | ||
67 | var name = collectionNames[i]; | ||
68 | var query = null; | ||
69 | |||
70 | // historical stats (stat.*) | ||
71 | if (name.indexOf('stat')==0) { | ||
72 | query = {time: {$lt:time_criteria}}; | ||
73 | } | ||
74 | |||
75 | if (query) { | ||
76 | count1 = db.getCollection(name).count(); | ||
77 | count2 = db.getCollection(name).find(query).count(); | ||
78 | print((dryrun ? "[dryrun] " : "") + "pruning " + count2 + " entries (total " + count1 + ") from " + name + "... "); | ||
79 | if (!dryrun) { | ||
80 | db.getCollection(name).remove(query); | ||
81 | db.runCommand({ compact: name }); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | if (!dryrun) db.repairDatabase(); | ||
87 | |||
diff --git a/non-free/unifi/unifi_db_prune.cron b/non-free/unifi/unifi_db_prune.cron new file mode 100755 index 0000000000..d5338835a5 --- /dev/null +++ b/non-free/unifi/unifi_db_prune.cron | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/sh | ||
2 | mongo --port 27117 < /etc/unifi/mongo_prune.js | ||