CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/compute/auto-restart.tsx
Views: 687
1
import { Alert, Checkbox, Switch } from "antd";
2
import { useEffect, useState } from "react";
3
import { Icon } from "@cocalc/frontend/components/icon";
4
import { A } from "@cocalc/frontend/components/A";
5
6
export default function AutoRestart({ setConfig, configuration, loading }) {
7
const [autoRestart, setAutoRestart] = useState<boolean>(
8
!!configuration.autoRestart,
9
);
10
const [help, setHelp] = useState<boolean>(false);
11
useEffect(() => {
12
setAutoRestart(configuration.autoRestart);
13
}, [configuration]);
14
return (
15
<div>
16
<div style={{ color: "#666", marginBottom: "5px" }}>
17
<div>
18
<b>
19
<Switch
20
size="small"
21
checkedChildren={"Help"}
22
unCheckedChildren={"Help"}
23
style={{ float: "right" }}
24
checked={help}
25
onChange={(val) => setHelp(val)}
26
/>
27
<Icon name="run" /> Automatically Restart
28
</b>
29
</div>
30
{help && (
31
<Alert
32
showIcon
33
style={{ margin: "15px 0" }}
34
type="info"
35
message={"Automatically Restart Compute Server"}
36
description={
37
<div>
38
<p>
39
Select this option and CoCalc will automatically restart your
40
compute server if it is killed, crashes or otherwise stops
41
pinging CoCalc.
42
</p>
43
{!!configuration["spot"] && (
44
<p>
45
This is useful if you are running a web server on a spot
46
instances, since spot instances will get killed when there
47
is a surge of usage by other people. Your compute server may
48
then automatically get started somewhere else in the data
49
center.
50
</p>
51
)}
52
<p>
53
You can use the{" "}
54
<A href="https://help.ubuntu.com/community/CronHowto">
55
standard crontab command line tool
56
</A>{" "}
57
(which is installed and fully supported for compute servers)
58
to start scripts or processes running whenever your server
59
restarts, or to periodically run a script.
60
</p>
61
</div>
62
}
63
/>
64
)}
65
<Checkbox
66
style={{ marginTop: "5px" }}
67
disabled={loading}
68
checked={autoRestart}
69
onChange={() => {
70
setConfig({ autoRestart: !autoRestart });
71
setAutoRestart(!autoRestart);
72
}}
73
>
74
Automatically Restart: restart compute server if it stops responding
75
</Checkbox>
76
</div>
77
</div>
78
);
79
}
80
81