MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / queueWeixinBridgeRestart

Function queueWeixinBridgeRestart

src/cli.ts:801–834  ·  view source on GitHub ↗
({
  stateDir = defaultCodexBridgeStateDir(),
  externalScopeId = null,
}: {
  stateDir?: string;
  externalScopeId?: string | null;
} = {})

Source from the content-addressed store, hash-verified

799}
800
801async function queueWeixinBridgeRestart({
802 stateDir = defaultCodexBridgeStateDir(),
803 externalScopeId = null,
804}: {
805 stateDir?: string;
806 externalScopeId?: string | null;
807} = {}) {
808 const i18n = createI18n();
809 if (externalScopeId) {
810 await enqueuePendingRestartNotification({
811 stateDir,
812 externalScopeId,
813 content: i18n.t('cli.serve.restartCompleted'),
814 });
815 }
816 const scriptPath = path.resolve(process.cwd(), 'scripts/service/restart-systemd-user.sh');
817 const unitName = `codexbridge-weixin-restart-${Date.now()}`;
818 const cwd = process.cwd();
819 const systemdStarted = await spawnDetached('systemd-run', [
820 '--user',
821 '--unit', unitName,
822 '--collect',
823 '/bin/bash',
824 scriptPath,
825 ], { cwd });
826 if (systemdStarted) {
827 return;
828 }
829
830 const fallbackStarted = await spawnDetached('/bin/bash', [scriptPath], { cwd });
831 if (!fallbackStarted) {
832 throw new Error(`Failed to schedule Weixin bridge restart with systemd-run or /bin/bash: ${scriptPath}`);
833 }
834}
835
836function spawnDetached(command: string, args: string[], { cwd }: { cwd: string }): Promise<boolean> {
837 return new Promise((resolve) => {

Callers 1

runWeixinServeFunction · 0.85

Calls 6

createI18nFunction · 0.85
spawnDetachedFunction · 0.85
resolveMethod · 0.80
tMethod · 0.65

Tested by

no test coverage detected