2019-11-09 23:05:34 -05:00
|
|
|
/* eslint-disable no-await-in-loop */
|
2019-12-18 23:47:08 -05:00
|
|
|
// import fs from 'fs-extra';
|
2019-12-20 12:18:19 -05:00
|
|
|
import { spawn } from 'child_process';
|
2019-11-09 23:05:34 -05:00
|
|
|
import { Client } from '..';
|
|
|
|
|
2019-11-09 23:46:21 -05:00
|
|
|
export default async function storage(client: Client) {
|
2019-12-18 23:47:08 -05:00
|
|
|
/* const main = async () => {
|
2019-11-09 23:05:34 -05:00
|
|
|
const accounts = await client.db.Account.find();
|
|
|
|
for (const account of accounts) {
|
2019-12-13 19:23:48 -05:00
|
|
|
setTimeout(async () => {
|
|
|
|
const res = await client.util.exec(`du -bs /home/${account.username}`);
|
|
|
|
let bytes = Number(res.split('/')[0].replace('\t', ''));
|
|
|
|
try {
|
|
|
|
await fs.access(`/var/mail/${account.username}`, fs.constants.F_OK);
|
|
|
|
const res2 = await client.util.exec(`du -bs /var/mail/${account.username}`);
|
|
|
|
bytes += Number(res2.split('/')[0].replace('\t', ''));
|
|
|
|
} catch {
|
|
|
|
bytes += 0;
|
|
|
|
}
|
|
|
|
await client.redis.set(`storage-${account.username}`, bytes);
|
|
|
|
}, 600000);
|
2019-11-09 23:05:34 -05:00
|
|
|
}
|
2019-11-09 23:13:49 -05:00
|
|
|
};
|
2019-11-09 23:46:21 -05:00
|
|
|
await main();
|
2019-11-09 23:13:49 -05:00
|
|
|
setInterval(async () => {
|
|
|
|
await main();
|
2019-12-18 23:47:08 -05:00
|
|
|
}, 900000); */
|
2019-12-20 12:18:19 -05:00
|
|
|
let storageGo = spawn('./storage', []);
|
|
|
|
storageGo.stdout.on('data', (data) => client.signale.log(data));
|
|
|
|
storageGo.stderr.on('data', (data) => client.signale.log(data));
|
|
|
|
storageGo.on('exit', (code) => {
|
|
|
|
client.signale.log(`Go storage func exited with code ${code}, restarting`);
|
|
|
|
storageGo = spawn('./storage', []);
|
|
|
|
});
|
2019-11-09 23:05:34 -05:00
|
|
|
}
|