File: killdaemons.py

package info (click to toggle)
mercurial 2.2.2-4%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 24,080 kB
  • sloc: python: 59,540; tcl: 3,635; ansic: 3,239; lisp: 1,412; sh: 800; makefile: 204; xml: 16
file content (25 lines) | stat: -rwxr-xr-x 603 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python

import os, time, errno, signal

# Kill off any leftover daemon processes
try:
    fp = open(os.environ['DAEMON_PIDS'])
    for line in fp:
        try:
            pid = int(line)
        except ValueError:
            continue
        try:
            os.kill(pid, 0)
            os.kill(pid, signal.SIGTERM)
            for i in range(10):
                time.sleep(0.05)
                os.kill(pid, 0)
            os.kill(pid, signal.SIGKILL)
        except OSError, err:
            if err.errno != errno.ESRCH:
                raise
    fp.close()
except IOError:
    pass