-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,74 @@ | ||
#!/usr/bin/env tsx | ||
import process from 'node:process' | ||
|
||
import arg from 'arg' | ||
import camelcaseKeys from 'camelcase-keys' | ||
|
||
import {cliClient} from './modules/cli-client.js' | ||
import Umbreld, {type UmbreldOptions} from './index.js' | ||
|
||
const showHelp = () => | ||
console.log(` | ||
Usage | ||
$ umbreld | ||
Options | ||
--help Shows this help message | ||
--data-directory Your Umbrel data directory | ||
--port The port to listen on | ||
--log-level The logging intensity: silent|normal|verbose | ||
--default-app-store-repo The default app store repository | ||
Examples | ||
$ umbreld --data-directory ~/umbrel | ||
`) | ||
|
||
const args = camelcaseKeys( | ||
arg({ | ||
'--help': Boolean, | ||
'--data-directory': String, | ||
'--port': Number, | ||
'--log-level': String, | ||
'--default-app-store-repo': String, | ||
}), | ||
) | ||
|
||
if (args.help) { | ||
showHelp() | ||
process.exit(0) | ||
} | ||
|
||
// TODO: Validate these args are valid | ||
const umbreld = new Umbreld(args as UmbreldOptions) | ||
|
||
// Shutdown cleanly on SIGINT and SIGTERM | ||
let isShuttingDown = false | ||
async function cleanShutdown(signal: string) { | ||
if (isShuttingDown) return | ||
isShuttingDown = true | ||
|
||
umbreld.logger.log(`Received ${signal}, shutting down cleanly...`) | ||
await umbreld.stop() | ||
process.exit(130) | ||
} | ||
process.on('SIGINT', cleanShutdown.bind(null, 'SIGINT')) | ||
process.on('SIGTERM', cleanShutdown.bind(null, 'SIGTERM')) | ||
|
||
let isRebooting = false | ||
async function doReboot(signal: string) { | ||
if (isRebooting) return | ||
isRebooting = true | ||
|
||
umbreld.logger.log(`Rebooting...`) | ||
await umbreld.stop() | ||
await umbreld.start() | ||
isRebooting = false | ||
} | ||
process.on('SIGUSR1', doReboot.bind(null, 'SIGUSR1')) | ||
|
||
try { | ||
await umbreld.start() | ||
} catch (error) { | ||
console.error(process.env.NODE_ENV === 'production' ? (error as Error).message : error) | ||
process.exit(1) | ||
} |