-
Notifications
You must be signed in to change notification settings - Fork 19
fix(startup): defer connect and temperature boot tasks #1988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elibosley
wants to merge
8
commits into
main
Choose a base branch
from
codex/defer-startup-tasks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
479d76f
fix(startup): defer connect and temperature boot tasks
elibosley 7e2739b
refactor(startup): remove zero-delay startup timers
elibosley 94bfa73
style(startup): fix prettier ordering in temperature tasks
elibosley c983f43
refactor(temperature): move app-ready startup into service
elibosley 119a822
test(temperature): update disk sensor availability spec
elibosley d454d08
test(connect): await empty startup task run
elibosley c1bfdd3
fix(cli): harden pm2 service lifecycle commands
elibosley 0729266
fix(plugin): create recovery archive during install
elibosley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { ECOSYSTEM_PATH } from '@app/environment.js'; | ||
| import { LogService } from '@app/unraid-api/cli/log.service.js'; | ||
| import { PM2Service } from '@app/unraid-api/cli/pm2.service.js'; | ||
| import { RestartCommand } from '@app/unraid-api/cli/restart.command.js'; | ||
| import { StartCommand } from '@app/unraid-api/cli/start.command.js'; | ||
| import { StatusCommand } from '@app/unraid-api/cli/status.command.js'; | ||
| import { StopCommand } from '@app/unraid-api/cli/stop.command.js'; | ||
|
|
||
| const createLogger = (): LogService => | ||
| ({ | ||
| trace: vi.fn(), | ||
| warn: vi.fn(), | ||
| error: vi.fn(), | ||
| log: vi.fn(), | ||
| info: vi.fn(), | ||
| debug: vi.fn(), | ||
| }) as unknown as LogService; | ||
|
|
||
| const createPm2Service = () => | ||
| ({ | ||
| run: vi.fn().mockResolvedValue({ stdout: '', stderr: '' }), | ||
| ensurePm2Dependencies: vi.fn().mockResolvedValue(undefined), | ||
| deleteDump: vi.fn().mockResolvedValue(undefined), | ||
| deletePm2Home: vi.fn().mockResolvedValue(undefined), | ||
| forceKillPm2Daemon: vi.fn().mockResolvedValue(undefined), | ||
| }) as unknown as PM2Service; | ||
|
|
||
| describe('PM2-backed CLI commands', () => { | ||
| it('start clears PM2 state and starts without mini-list', async () => { | ||
| const logger = createLogger(); | ||
| const pm2 = createPm2Service(); | ||
| const command = new StartCommand(logger, pm2); | ||
|
|
||
| await command.run([], { logLevel: 'info' }); | ||
|
|
||
| expect(pm2.ensurePm2Dependencies).toHaveBeenCalledTimes(1); | ||
| expect(pm2.deleteDump).toHaveBeenCalledTimes(1); | ||
| expect(pm2.deletePm2Home).toHaveBeenCalledTimes(1); | ||
| expect(pm2.run).toHaveBeenNthCalledWith(1, { tag: 'PM2 Stop' }, 'stop', ECOSYSTEM_PATH); | ||
| expect(pm2.run).toHaveBeenNthCalledWith(2, { tag: 'PM2 Update' }, 'update'); | ||
| expect(pm2.run).toHaveBeenNthCalledWith(3, { tag: 'PM2 Delete' }, 'delete', ECOSYSTEM_PATH); | ||
| expect(pm2.run).toHaveBeenNthCalledWith(4, { tag: 'PM2 Kill' }, 'kill', '--no-autorestart'); | ||
| expect(pm2.run).toHaveBeenNthCalledWith( | ||
| 5, | ||
| { tag: 'PM2 Start', raw: true, extendEnv: true, env: { LOG_LEVEL: 'info' } }, | ||
| 'start', | ||
| ECOSYSTEM_PATH, | ||
| '--update-env' | ||
| ); | ||
| expect(vi.mocked(pm2.run).mock.calls.flat()).not.toContain('--mini-list'); | ||
| }); | ||
|
|
||
| it('restart omits mini-list from the PM2 restart call', async () => { | ||
| const logger = createLogger(); | ||
| const pm2 = createPm2Service(); | ||
| const command = new RestartCommand(logger, pm2); | ||
|
|
||
| await command.run([], { logLevel: 'info' }); | ||
|
|
||
| expect(pm2.run).toHaveBeenCalledWith( | ||
| { tag: 'PM2 Restart', raw: true, extendEnv: true, env: { LOG_LEVEL: 'info' } }, | ||
| 'restart', | ||
| ECOSYSTEM_PATH, | ||
| '--update-env' | ||
| ); | ||
| expect(vi.mocked(pm2.run).mock.calls.flat()).not.toContain('--mini-list'); | ||
| }); | ||
|
|
||
| it('status omits mini-list from the PM2 status call', async () => { | ||
| const pm2 = createPm2Service(); | ||
| const command = new StatusCommand(pm2); | ||
|
|
||
| await command.run(); | ||
|
|
||
| expect(pm2.run).toHaveBeenCalledWith( | ||
| { tag: 'PM2 Status', stdio: 'inherit', raw: true }, | ||
| 'status', | ||
| 'unraid-api' | ||
| ); | ||
| expect(vi.mocked(pm2.run).mock.calls.flat()).not.toContain('--mini-list'); | ||
| }); | ||
|
|
||
| it('stop omits mini-list from the PM2 delete call', async () => { | ||
| const pm2 = createPm2Service(); | ||
| const command = new StopCommand(pm2); | ||
|
|
||
| await command.run([], { delete: false }); | ||
|
|
||
| expect(pm2.run).toHaveBeenCalledWith( | ||
| { tag: 'PM2 Delete', stdio: 'inherit' }, | ||
| 'delete', | ||
| ECOSYSTEM_PATH, | ||
| '--no-autorestart' | ||
| ); | ||
| expect(vi.mocked(pm2.run).mock.calls.flat()).not.toContain('--mini-list'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also force-kill the PM2 daemon before deleting
PM2_HOME.The hardened
stop --deletepath already doespm2 killthenforceKillPm2Daemon()thendeletePm2Home(). SkippingforceKillPm2Daemon()here means the new startup-recovery path can still race a stuck daemon and fail to clear the old state cleanly.Suggested fix
await this.pm2.run({ tag: 'PM2 Delete' }, 'delete', ECOSYSTEM_PATH); await this.pm2.run({ tag: 'PM2 Kill' }, 'kill', '--no-autorestart'); + await this.pm2.forceKillPm2Daemon(); await this.pm2.deletePm2Home();📝 Committable suggestion
🤖 Prompt for AI Agents