|
@@ -213,7 +213,7 @@ class SystemctlController extends Controller {
|
|
|
if (res.errcode === 0) {
|
|
|
this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
} else {
|
|
|
- this.ctx.body = { errcode: -1, errmsg: '操作失败' };
|
|
|
+ this.ctx.body = { errcode: -1034, errmsg: '操作失败' };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
const body = { errcode: -1034, errmsg: '操作失败', error };
|
|
@@ -231,6 +231,32 @@ class SystemctlController extends Controller {
|
|
|
throw new Error(JSON.stringify(body));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 设置时间同步
|
|
|
+ async setNtp() {
|
|
|
+ const { status } = this.ctx.request.body;
|
|
|
+ try {
|
|
|
+ await this.service.shell.shell(shells.setNtp(status || 'no'));
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok' };
|
|
|
+ } catch (error) {
|
|
|
+ const body = { errcode: -1036, errmsg: `${status === 'yes' ? '启用' : '停用'}时间同步失败`, error };
|
|
|
+ throw new Error(JSON.stringify(body));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获得NTP设置
|
|
|
+ async getNtp() {
|
|
|
+ try {
|
|
|
+ const res = await this.service.shell.shell(shells.getNtp);
|
|
|
+ if (res.errcode === 0) {
|
|
|
+ this.ctx.body = { errcode: 0, errmsg: 'ok', data: res.data };
|
|
|
+ } else {
|
|
|
+ this.ctx.body = { errcode: -1037, errmsg: '获得NTP设置失败' };
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ const body = { errcode: -1037, errmsg: '获得NTP设置失败', error };
|
|
|
+ throw new Error(JSON.stringify(body));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = SystemctlController;
|