forked from HeyPuter/puter
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d0e461e
commit 0250469
Showing
11 changed files
with
352 additions
and
104 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,42 @@ | ||
const { Context } = require("../util/context"); | ||
const BaseService = require("./BaseService"); | ||
|
||
class BootScriptService extends BaseService { | ||
static MODULES = { | ||
fs: require('fs'), | ||
} | ||
async ['__on_boot.ready'] () { | ||
const args = Context.get('args'); | ||
if ( ! args['boot-script'] ) return; | ||
const script_name = args['boot-script']; | ||
|
||
const require = this.require; | ||
const fs = require('fs'); | ||
const boot_json_raw = fs.readFileSync(script_name, 'utf8'); | ||
const boot_json = JSON.parse(boot_json_raw); | ||
await this.run_script(boot_json); | ||
} | ||
|
||
async run_script (boot_json) { | ||
const scope = { | ||
runner: 'boot-script', | ||
['end-puter-process']: ({ args }) => { | ||
const svc_shutdown = this.services.get('shutdown'); | ||
svc_shutdown.shutdown(args[0]); | ||
} | ||
}; | ||
|
||
for ( let i=0 ; i < boot_json.length ; i++ ) { | ||
const statement = boot_json[i]; | ||
const [cmd, ...args] = statement; | ||
if ( ! scope[cmd] ) { | ||
throw new Error(`Unknown command: ${cmd}`); | ||
} | ||
await scope[cmd]({ scope, args }); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
BootScriptService | ||
}; |
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,11 @@ | ||
const BaseService = require("./BaseService"); | ||
|
||
class ShutdownService extends BaseService { | ||
shutdown ({ reason, code } = {}) { | ||
this.log.info(`Puter is shutting down: ${reason ?? 'no reason provided'}`); | ||
process.stdout.write('\x1B[0m\r\n'); | ||
process.exit(code ?? 0); | ||
} | ||
} | ||
|
||
module.exports = { ShutdownService }; |
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
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
Oops, something went wrong.