forked from mark-lightfoot/python-systemd-http-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
executable file
·45 lines (40 loc) · 1.22 KB
/
deploy.py
File metadata and controls
executable file
·45 lines (40 loc) · 1.22 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
#!/usr/bin/python
from shutil import rmtree
import os
import time
import stat
import signal
import subprocess
from shutil import rmtree
from shutil import copyfile
from shutil import copytree
from os.path import expanduser
project = "python-http-server"
install_location = expanduser("~") + "/deployments/" + project
# kill running process
pid_file_location = install_location + "/PID"
if os.path.isfile(pid_file_location):
with open(pid_file_location, "r") as pid_file:
pid = pid_file.read()
print("killing process: " + pid)
try:
os.kill(int(pid), signal.SIGTERM)
except OSError as e:
print(e)
# remove old installation
if os.path.isdir(install_location):
rmtree(install_location)
# install application
os.makedirs(install_location)
copytree("public", install_location + "/public")
application_binary = install_location + "/app.py"
copyfile("app.py", application_binary)
permissions = stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR
os.chmod(application_binary, permissions)
# run application
cmd = "nohup bash -c " + application_binary + " & disown"
proc = subprocess.Popen(cmd, shell=True)
with open(pid_file_location, "w") as pid_file:
pid_file.write(str(proc.pid))
print("new application started: " + str(proc.pid))
proc.wait()