@@ -57,7 +57,7 @@ Index: sagemaker-code-editor/vscode/src/vs/server/node/webClientServer.ts
5757+ * Handles API requests to run the post-startup script in SMD.
5858+ */
5959+ private async _handlePostStartupScriptInvocation(req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {
60- + const postStartupScripPath = '/etc/sagemaker-ui/sagemaker_ui_post_startup.sh'
60+ + const postStartupScriptPath = '/etc/sagemaker-ui/sagemaker_ui_post_startup.sh'
6161+ const logPath = '/var/log/apps/post_startup_default.log';
6262+ const logStream = fs.createWriteStream(logPath, { flags: 'a' });
6363+
@@ -68,19 +68,19 @@ Index: sagemaker-code-editor/vscode/src/vs/server/node/webClientServer.ts
6868+ //If postStartupScriptFile doesn't exist, it will throw FileNotFoundError (404)
6969+ //If exists, it will start the execution and add the execution logs in logFile.
7070+ try {
71- + if (fs.existsSync(postStartupScripPath )) {
71+ + if (fs.existsSync(postStartupScriptPath )) {
7272+ // Adding 0o755 to make script file executable
73- + fs.chmodSync(postStartupScripPath , 0o755);
73+ + fs.chmodSync(postStartupScriptPath , 0o755);
7474+
75- + const subprocess = spawn('bash', [`${postStartupScripPath }`], { cwd: '/' });
75+ + const subprocess = spawn('bash', [`${postStartupScriptPath }`], { cwd: '/' });
7676+ subprocess.stdout.pipe(logStream);
7777+ subprocess.stderr.pipe(logStream);
7878+
7979+ res.statusCode = 200;
8080+ res.setHeader('Content-Type', 'application/json');
8181+ res.end(JSON.stringify({ 'success': 'true' }));
8282+ } else {
83- + serveError(req, res, 500, 'Poststartup script file not found at ' + postStartupScripPath );
83+ + serveError(req, res, 500, 'Poststartup script file not found at ' + postStartupScriptPath );
8484+ }
8585+ } catch (error) {
8686+ serveError(req, res, 500, error.message);
0 commit comments