Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/smc_pyutil/smc_pyutil/stop_smc.py
Views: 285
1
#!/usr/bin/env python3
2
# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
# License: AGPLv3 s.t. "Commons Clause" – read LICENSE.md for details
4
5
from __future__ import absolute_import
6
from __future__ import print_function
7
import os, sys
8
9
if not 'SMC' in os.environ:
10
os.environ['SMC'] = os.path.join(os.environ['HOME'], '.smc')
11
SMC = os.environ['SMC']
12
13
14
def cmd(s):
15
print(s)
16
if os.system(s):
17
sys.exit(1)
18
19
20
def remove_port_files():
21
print("Remove port files.")
22
for x in os.listdir(SMC):
23
p = os.path.join(SMC, x)
24
if os.path.isdir(p):
25
for y in os.listdir(p):
26
if y.endswith('.port'):
27
os.unlink(os.path.join(p, y))
28
29
30
def stop_daemons():
31
print("stop daemons")
32
cmd("smc-local-hub stop")
33
cmd("smc-sage-server stop")
34
35
36
def main():
37
remove_port_files()
38
stop_daemons()
39
40
41
if __name__ == "__main__":
42
main()
43
44