Skip to content

Commit

Permalink
feat: 更新站点重启 waline 服务
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Sep 1, 2022
1 parent 29fdb23 commit 2c982b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { UpdateSiteInfoDto } from 'src/dto/site.dto';
import { AdminGuard } from 'src/provider/auth/auth.guard';
import { ISRProvider } from 'src/provider/isr/isr.provider';
import { MetaProvider } from 'src/provider/meta/meta.provider';
import { WalineProvider } from 'src/provider/waline/waline.provider';
@ApiTags('site')
@UseGuards(AdminGuard)
@Controller('/api/admin/meta/site')
export class SiteMetaController {
constructor(
private readonly metaProvider: MetaProvider,
private readonly isrProvider: ISRProvider,
private readonly walineProvider: WalineProvider,
) {}

@Get()
Expand All @@ -26,6 +28,7 @@ export class SiteMetaController {
async update(@Body() updateDto: UpdateSiteInfoDto) {
const data = await this.metaProvider.updateSiteInfo(updateDto);
this.isrProvider.activeAll('更新站点配置触发增量渲染!');
this.walineProvider.restart('更新站点,');
return {
statusCode: 200,
data,
Expand Down
11 changes: 10 additions & 1 deletion packages/server/src/provider/waline/waline.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ export class WalineProvider {
async init() {
this.run();
}
async restart(reason: string) {
this.logger.log(`${reason}重启 waline`);
if (this.ctx) {
await this.stop();
}
await this.run();
}
async stop() {
if (this.ctx) {
this.ctx.kill('SIGINT');
this.ctx.unref();
process.kill(-this.ctx.pid);
this.ctx = null;
this.logger.log('waline 停止成功!');
}
Expand All @@ -46,6 +54,7 @@ export class WalineProvider {
...this.env,
},
cwd: process.cwd(),
detached: true,
});
this.ctx.on('message', (message) => {
this.logger.log(message);
Expand Down

0 comments on commit 2c982b0

Please sign in to comment.