[platform] ignore SIGHUP in restarter script (IDEA-162263)
[idea/community.git] / bin / linux / restart.py
1 #!/usr/bin/env python
2
3 # Waits for the parent process to terminate, then executes specified commands.
4
5 import os
6 import signal
7 import sys
8 import time
9
10 if len(sys.argv) < 3:
11     raise Exception('usage: restart.py <pid> <path> [optional command]')
12
13 signal.signal(signal.SIGHUP, signal.SIG_IGN)
14
15 pid = int(sys.argv[1])
16 while os.getppid() == pid:
17     time.sleep(0.5)
18
19 if len(sys.argv) > 3:
20     os.spawnv(os.P_WAIT, sys.argv[3], sys.argv[3:])
21
22 to_launch = sys.argv[2]
23 if sys.platform == 'darwin':
24     os.execv('/usr/bin/open', ['/usr/bin/open', to_launch])
25 else:
26     os.execv(to_launch, [to_launch])