mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
* repeatable command launch fn * allow js fn for daemon exec * improve daemon init system * fixes from testing
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import * as T from "../../../base/lib/types"
|
|
import { SubContainer, SubContainerOwned } from "../util/SubContainer"
|
|
import { CommandController } from "./CommandController"
|
|
import { Daemon } from "./Daemon"
|
|
import { DaemonCommandType } from "./Daemons"
|
|
|
|
/**
|
|
* This is a wrapper around CommandController that has a state of off, where the command shouldn't be running
|
|
* and the others state of running, where it will keep a living running command
|
|
* unlike Daemon, does not restart on success
|
|
*/
|
|
|
|
export class Oneshot<Manifest extends T.SDKManifest> extends Daemon<Manifest> {
|
|
static of<Manifest extends T.SDKManifest>() {
|
|
return async (
|
|
effects: T.Effects,
|
|
subcontainer: SubContainer<Manifest>,
|
|
exec: DaemonCommandType | null,
|
|
) => {
|
|
if (subcontainer.isOwned()) subcontainer = subcontainer.rc()
|
|
const startCommand = exec
|
|
? () =>
|
|
CommandController.of<Manifest>()(effects, subcontainer.rc(), exec)
|
|
: null
|
|
return new Oneshot(subcontainer, startCommand, true)
|
|
}
|
|
}
|
|
}
|