Skip to content

Commit 84b6842

Browse files
committed
Move restart service to util
1 parent 8dd2d5b commit 84b6842

4 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/bootstrap/repair.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import shell from 'shelljs';
2-
31
import InstallationService from '@/service/installation';
42
import { MySQLCredential } from '@/type/common';
3+
import { restartNginxService, restartPHPFPMService } from '@/util/unix';
54

65
export default class RepairBootstrap {
76
static async handler(directory: string, domain: string, database: MySQLCredential) {
@@ -12,12 +11,7 @@ export default class RepairBootstrap {
1211
database
1312
);
1413

15-
if (shell.exec(`systemctl restart nginx`).code !== 0) {
16-
throw new Error('Failed to restart php service');
17-
}
18-
19-
if (shell.exec(`systemctl restart php${phpVer}-fpm`).code !== 0) {
20-
throw new Error('Failed to restart php service');
21-
}
14+
restartNginxService();
15+
restartPHPFPMService(phpVer);
2216
}
2317
}

src/bootstrap/setup.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { rimrafSync } from 'rimraf';
4-
import shell from 'shelljs';
54

65
import HTTPService from '@/service/http';
76
import InstallationService from '@/service/installation';
87
import { MySQLCredential, WPTemplate } from '@/type/common';
8+
import { restartNginxService, restartPHPFPMService } from '@/util/unix';
99
import { unzip } from '@/util/zip';
1010

1111
export default class SetupBootstrap {
@@ -58,12 +58,7 @@ export default class SetupBootstrap {
5858
database
5959
);
6060

61-
if (shell.exec(`systemctl restart nginx`).code !== 0) {
62-
throw new Error('Failed to restart php service');
63-
}
64-
65-
if (shell.exec(`systemctl restart php${phpVer}-fpm`).code !== 0) {
66-
throw new Error('Failed to restart php service');
67-
}
61+
restartNginxService();
62+
restartPHPFPMService(phpVer);
6863
}
6964
}

src/error/RestartServiceError.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default class RestartServiceError extends Error {}

src/util/unix.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import shell from 'shelljs';
33
import { getPHPErrorLogPath } from './path';
44

55
import PHPVersionNotFoundError from '@/error/PHPVersionNotFoundError';
6+
import RestartServiceError from '@/error/RestartServiceError';
67

78
export function isPHPInstalled() {
89
return shell.which('php');
@@ -12,6 +13,18 @@ export function isMySQLInstalled() {
1213
return shell.which('mysqld');
1314
}
1415

16+
export function restartNginxService() {
17+
if (shell.exec(`systemctl restart nginx`).code !== 0) {
18+
throw new RestartServiceError('nginx');
19+
}
20+
}
21+
22+
export function restartPHPFPMService(phpVer: string) {
23+
if (shell.exec(`systemctl restart php${phpVer}-fpm`).code !== 0) {
24+
throw new RestartServiceError('php-fpm');
25+
}
26+
}
27+
1528
export function createPHPErrorLogFile(phpVer: string, identity: string) {
1629
const path = getPHPErrorLogPath(phpVer, identity);
1730
shell.touch(path);

0 commit comments

Comments
 (0)