-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfigStartup.py
More file actions
47 lines (41 loc) · 1.6 KB
/
ConfigStartup.py
File metadata and controls
47 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Creates shell script that will allow startup.py script to be executed automatically upon bootup
import os
def ConfigCondaEnvVars(filepath):
os.chdir("$CONDA_PREFIX")
# Setup the activate file
os.system("mkdir -p ./etc/conda/activate.d")
os.system("touch ./etc/conda/activate.d/env_vars.sh")
env_var = open("./etc/conda/activate.d/env_vars.sh")
env_var.write("#!/bin/sh\nexport MY_FILE=%s", filepath)
# Setup the deactivate file
os.system("mkdir -p ./etc/conda/deactivate.d")
os.system("touch ./etc/conda/deactivate.d/env_vars.sh")
env_var = open("./etc/conda/activate.d/env_vars.sh")
env_var.write("#!/bin/sh\nunset %s", filepath)
def MakeStartup(filename):
ConfigCondaEnvVars( ("/usr/bin/"+filename) )
os.chdir("/usr/bin/")
f = open("startup.sh","w+")
f.write("#!/bin/bash\n"+
"%s/etc/conda/activate.d/%s" % filename)
f.close()
os.system("chmod u+x /usr/bin/%s", filename)
MakeService(filename)
def MakeService(filename):
f = open("/lib/systemd/%s.service", filename)
f.write("[Unit]\n"+
"Description=Startup Script\n"+
"[Service]\n"+
"Type=simple\n"+
"ExecStart=/usr/bin/%s.sh\n"+
"[Install]\n"+
"WantedBy=multi-user.target", filename)
f.close()
os.chdir("/etc/systemd/system/")
os.system("ln /lib/systemd/%s.service %s.service", filename, filename)
SetConfig(filename)
def SetConfig(filename):
os.system("systemctl daemon-reload")
os.system("systemctl start %s.service", filename)
os.system("systemctl enable %s.service", filename)
MakeStartup("startup")