forked from bantosik/python_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrashing.py
More file actions
executable file
·43 lines (31 loc) · 827 Bytes
/
Copy pathcrashing.py
File metadata and controls
executable file
·43 lines (31 loc) · 827 Bytes
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
#!/usr/bin/env python
import sys
import signal
import os
import datetime
import time
import crashingCommon
FILE_NAME = 'lockfile'
pidfile = crashingCommon.get_pidfile(sys.argv)
def cleanup(signum, frame):
os.remove(pidfile)
if signum == signal.SIGTERM:
sys.exit(0)
else:
sys.exit(1)
if os.path.isfile(pidfile):
sys.stderr.write("Cannot continue pidfile for instance already exists")
sys.exit(1)
else:
with open(pidfile, 'w+') as f:
f.write(str(os.getpid()))
signal.signal(signal.SIGTERM, cleanup)
signal.signal(signal.SIGUSR1, cleanup)
while os.path.isfile(FILE_NAME):
sys.stdout.write(format(datetime.datetime.now()) + " Hello changed yes!\n")
sys.stdout.flush()
time.sleep(1)
cleanup(None, None)
sys.stderr.write("No lockfile")
sys.stderr.flush()
sys.exit(1)