({
stateDir = defaultCodexBridgeStateDir(),
externalScopeId = null,
}: {
stateDir?: string;
externalScopeId?: string | null;
} = {})
| 799 | } |
| 800 | |
| 801 | async 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 | |
| 836 | function spawnDetached(command: string, args: string[], { cwd }: { cwd: string }): Promise<boolean> { |
| 837 | return new Promise((resolve) => { |
no test coverage detected