wisdom #44
@@ -28,6 +28,7 @@
|
|||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"crypto": "^1.0.1",
|
"crypto": "^1.0.1",
|
||||||
|
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"exceljs": "^4.4.0",
|
"exceljs": "^4.4.0",
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ const {
|
|||||||
const { getErrorCodeByBrandAndCodeDb } = require("../db/brand_code.db");
|
const { getErrorCodeByBrandAndCodeDb } = require("../db/brand_code.db");
|
||||||
const { getDeviceNotificationByIdDb } = require("../db/notification_error.db");
|
const { getDeviceNotificationByIdDb } = require("../db/notification_error.db");
|
||||||
|
|
||||||
|
const { exec } = require("child_process");
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
const exec = util.promisify(require("child_process").exec);
|
const execPromise = util.promisify(exec);
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
@@ -150,36 +151,43 @@ class NotifikasiWaService {
|
|||||||
async restartWhatsapp() {
|
async restartWhatsapp() {
|
||||||
try {
|
try {
|
||||||
const processName = "Whatsapp-API-notification";
|
const processName = "Whatsapp-API-notification";
|
||||||
|
const { stdout } = await execPromise("pm2 jlist");
|
||||||
const { stdout } = await exec("pm2 jlist");
|
|
||||||
|
|
||||||
const processes = JSON.parse(stdout);
|
const processes = JSON.parse(stdout);
|
||||||
const waProcess = processes.find((p) => p.name === processName);
|
const waProcess = processes.find((p) => p.name === processName);
|
||||||
|
|
||||||
if (!waProcess) {
|
if (!waProcess) throw new Error(`PM2 ${processName} not found`);
|
||||||
throw new Error("PM2 Not Found");
|
|
||||||
}
|
|
||||||
|
|
||||||
const processId = waProcess.pm_id;
|
const waProcessId = waProcess.pm_id;
|
||||||
|
const pathDelete = waProcess.pm2_env.pm_cwd;
|
||||||
|
|
||||||
await exec(`pm2 stop ${processId}`);
|
// const execLogs = (cmd) => {
|
||||||
|
// const p = exec(cmd);
|
||||||
|
// p.stdout.pipe(process.stdout);
|
||||||
|
// p.stderr.pipe(process.stderr);
|
||||||
|
// return new Promise((res) => p.on("exit", res));
|
||||||
|
// };
|
||||||
|
|
||||||
const pathsToDelete = [
|
// console.log(`stop proses id: ${waProcessId}`)
|
||||||
path.join(__dirname, ".wwebjs_auth"),
|
await execPromise(`start powershell -Command "pm2 stop ${waProcessId}"`);
|
||||||
path.join(__dirname, ".wwebjs_cache"),
|
|
||||||
|
const pathFolderDelete = [
|
||||||
|
path.join(pathDelete, ".wwebjs_auth"),
|
||||||
|
path.join(pathDelete, ".wwebjs_cache"),
|
||||||
];
|
];
|
||||||
|
|
||||||
pathsToDelete.forEach((dir) => {
|
// console.log(`path: ${pathDelete}`);
|
||||||
|
|
||||||
|
pathFolderDelete.forEach((dir) => {
|
||||||
if (fs.existsSync(dir)) {
|
if (fs.existsSync(dir)) {
|
||||||
|
// console.log(`path folder: ${dir}`);
|
||||||
fs.rmSync(dir, { recursive: true, force: true });
|
fs.rmSync(dir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await exec(`pm2 restart ${processId}`);
|
// console.log(`start proses id: ${waProcessId}`);
|
||||||
return {
|
await execPromise(`start powershell -Command "pm2 restart ${waProcessId}"`);
|
||||||
success: true,
|
|
||||||
message: `WhatsApp has been restart.`,
|
return { success: true, message: "WhatsApp has been restarted." };
|
||||||
};
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user