-
Notifications
You must be signed in to change notification settings - Fork 0
/
restartBT
executable file
·38 lines (31 loc) · 1.01 KB
/
restartBT
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
#!/usr/bin/python3
"""
NB restart requires that BT is on PATH
and export PYTHONPATH=/path/to/Vcourse/lib is needed
and the working directory needs to have config files,
so the restart is attempted in the original dir which
is the second line of the pid file.
If the pid file does not exist (hopefully the process is
not running) then start is attempted in the pwd.
"""
# License GPL 2. Copyright Paul D. Gilbert, 2018
import os
import signal
import time
import sys
import subprocess
pidfile = os.getenv("HOME") + '/.BT.pid'
pid = ['', os.getenv("PWD")] # for case process is not running
try:
with open(pidfile, 'r') as f: pid = f.read().splitlines()
except:
print('pid file ' + pidfile+ ' read error. Process probably not running.')
try:
os.kill(int(pid[0]), signal.SIGTERM)
os.remove(pidfile)
time.sleep(5)
except:
print('kill failed. Process probably not running.')
print('will attempt to start process in pwd.')
npid = subprocess.Popen('BT', cwd=pid[1]).pid
print(npid)