Skip to content

Commit 8881d59

Browse files
committed
fix stopping projects in single user mode
1 parent a01ff06 commit 8881d59

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/packages/server/projects/control/single-user.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@ This is useful for:
1414
- development of cocalc from inside of a CoCalc project
1515
- non-collaborative use of cocalc on your own
1616
laptop, e.g., when you're on an airplane.
17-
18-
17+
18+
1919
DEVELOPMENT:
2020
2121
2222
~/cocalc/src/packages/server/projects/control$ COCALC_MODE='single-user' node
2323
Welcome to Node.js v20.19.1.
2424
Type ".help" for more information.
25-
> a = require('@cocalc/server/projects/control');
25+
> a = require('@cocalc/server/projects/control');
2626
> p = a.getProject('8a840733-93b6-415c-83d4-7e5712a6266b')
2727
> await p.start()
2828
*/
2929

30-
import { kill } from "process";
31-
30+
import { kill } from "node:process";
3231
import getLogger from "@cocalc/backend/logger";
3332
import {
3433
BaseProject,
@@ -153,16 +152,26 @@ class Project extends BaseProject {
153152
try {
154153
this.stateChanging = { state: "stopping" };
155154
await this.saveStateToDatabase(this.stateChanging);
156-
try {
157-
const pid = await getProjectPID(this.HOME);
158-
logger.debug(`stop: sending kill -${pid}`);
159-
kill(-pid);
160-
} catch (err) {
161-
// expected exception if no pid
162-
logger.debug(`stop: kill err ${err}`);
163-
}
155+
const pid = await getProjectPID(this.HOME);
156+
const killProject = () => {
157+
try {
158+
logger.debug(`stop: sending kill -${pid}`);
159+
kill(-pid, "SIGKILL");
160+
} catch (err) {
161+
// expected exception if no pid
162+
logger.debug(`stop: kill err ${err}`);
163+
}
164+
};
165+
killProject();
164166
await this.wait({
165-
until: async () => !(await isProjectRunning(this.HOME)),
167+
until: async () => {
168+
if (await isProjectRunning(this.HOME)) {
169+
killProject();
170+
return false;
171+
} else {
172+
return true;
173+
}
174+
},
166175
maxTime: MAX_STOP_TIME_MS,
167176
});
168177
await deleteProjectSecretToken(this.project_id);

0 commit comments

Comments
 (0)