mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09:38:19 +08:00
core: implement postRestart
This commit is contained in:
1 parent
adce12e212
commit
040205045f
3 files changed
+14
-6
No files matched your search
@@ -40,8 +40,9 @@ if (argv._[0] === 'backup') {
|
||||
const url = buildUrl(JSON.parse(dbConfig));
|
||||
const dir = `${os.tmpdir()}/${Math.random().toString(36).substring(2)}`;
|
||||
exec('mongodump', [url, `--out=${dir}/dump`], { stdio: 'inherit' });
|
||||
const env = `${os.homedir()}/.hydro/env`;
|
||||
if (fs.existsSync(env)) fs.copySync(env, `${dir}/env`);
|
||||
// Do not backup .env & config.json as they are all related to local installation
|
||||
const env = `${os.homedir()}/.hydro/addon.json`;
|
||||
if (fs.existsSync(env)) fs.copySync(env, `${dir}/addon.json`);
|
||||
const target = `${process.cwd()}/backup-${new Date().toISOString().replace(':', '-').split(':')[0]}.zip`;
|
||||
exec('zip', ['-r', target, 'dump'], { cwd: dir, stdio: 'inherit' });
|
||||
if (!argv.dbOnly) {
|
||||
@@ -66,8 +67,8 @@ if (argv._[0] === 'restore') {
|
||||
exec('rm', ['-rf', '/data/file/*'], { stdio: 'inherit' });
|
||||
exec('bash', ['-c', `mv ${dir}/file/* /data/file`], { stdio: 'inherit' });
|
||||
}
|
||||
if (fs.existsSync(`${dir}/env`)) {
|
||||
fs.copySync(`${dir}/env`, `${os.homedir()}/.hydro/env`, { overwrite: true });
|
||||
if (fs.existsSync(`${dir}/addon.json`)) {
|
||||
fs.copySync(`${dir}/addon.json`, `${os.homedir()}/.hydro/addon.json`, { overwrite: true });
|
||||
}
|
||||
fs.removeSync(dir);
|
||||
console.log('Successfully restored.');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.10.5",
|
||||
"version": "3.10.6",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { exec } from 'child_process';
|
||||
import { inspect } from 'util';
|
||||
import Ajv from 'ajv';
|
||||
import * as yaml from 'js-yaml';
|
||||
import * as check from '../check';
|
||||
import { ValidationError } from '../error';
|
||||
import { BadRequestError, ValidationError } from '../error';
|
||||
import {
|
||||
isEmail, isPassword, isUname, validate,
|
||||
} from '../lib/validator';
|
||||
@@ -86,6 +87,12 @@ class SystemDashboardHandler extends SystemHandler {
|
||||
async get() {
|
||||
this.response.template = 'manage_dashboard.html';
|
||||
}
|
||||
|
||||
async postRestart() {
|
||||
if (!process.env.pm_cwd) throw new BadRequestError('Not launched by pm2');
|
||||
exec(`pm2 reload "${process.env.name}"`);
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
|
||||
class SystemScriptHandler extends SystemHandler {
|
||||
|
||||
Reference in new issue
Block a user