awips2/cave/com.raytheon.viz.avnconfig/localization/aviation/python/avnkill.py
Max Schenkelberg 3c02342d04 Issue #2033 moved avnfps and text workstation files into respective plugins.
Change-Id: If95cb839ad81ca2a842ff7f6926847ac3928d8f2

Former-commit-id: db24201469 [formerly bbad83c21a] [formerly 6f60751ec6] [formerly db24201469 [formerly bbad83c21a] [formerly 6f60751ec6] [formerly c5575f9624 [formerly 6f60751ec6 [formerly 77e1a4d8f5237e5fae930c1e00589c752f8b3738]]]]
Former-commit-id: c5575f9624
Former-commit-id: 62f4f1bafb [formerly 8139e0dfb7] [formerly 33159773a1764cd4fb517d13a3cff0a11feaa433 [formerly 8de539020d]]
Former-commit-id: 094fceec6e1d9989f5e80a4efe1310f8a093b3ef [formerly 451eb54a36]
Former-commit-id: f553c93092
2013-08-15 12:21:43 -05:00

119 lines
3.3 KiB
Python

##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
##
#
# Name:
# avnkill.py
# GFS1-NHD:A8264.0000-SCRIPT;3
#
# Status:
# DELIVERED
#
# History:
# Revision 3 (DELIVERED)
# Created: 07-MAY-2005 11:41:19 OBERFIEL
# Added Item Header Block
#
# Revision 2 (DELIVERED)
# Created: 04-APR-2005 13:48:51 TROJAN
# spr 6779
#
# Revision 1 (DELIVERED)
# Created: 23-JAN-2005 18:50:15 TROJAN
# spr 6604
#
# Change Document History:
# 1:
# Change Document: GFS1-NHD_SPR_6832
# Action Date: 07-JUN-2005 13:13:53
# Relationship Type: In Response to
# Status: CLOSED
# Title: AvnFPS: Add PVCS doc blocks
#
#
# avnkill.py
# kills avnpython processes
# George Trojan, SAIC/MDL, September 2004
# last update: 03/30/05
import os, signal, sys, time
import ConfigParser
TopDir = os.environ['TOP_DIR']
sys.path = sys.path[1:]
sys.path.extend([os.path.join(TopDir, dir) for dir in \
['sitepy', 'py', 'toolpy']])
import AvnUtils
def getPPid(pid):
path = '/proc/%d/status' % pid
for line in file(path):
if line.startswith('PPid'):
ppid = line.split()[-1]
return int(ppid)
return 0
def kill(sig=None):
for d in os.listdir('/proc'):
try:
pid = int(d)
path = '/proc/%d/cmdline' % pid
line = file(path).read().replace('\0', ' ')
if line.startswith('avnpython'):
ppid = getPPid(pid)
if ppid == 1:
if sig is not None:
print 'Killing', line
os.kill(pid, sig)
else:
print line
except (IOError, ValueError):
pass
def killAll():
print 'Killing all avnpython processes'
print 'Using SIGTERM'
kill(signal.SIGTERM)
time.sleep(30.0)
print 'Using SIGKILL'
kill(signal.SIGKILL)
print 'Remaining processes'
kill()
def killServers(host):
print 'Killing server processes on host', host
args = ['avninit.py', host]
for pid in AvnUtils.isRunning(args):
print 'Using SIGTERM', pid
os.kill(pid, signal.SIGTERM)
time.sleep(5)
for pid in AvnUtils.isRunning(args):
print 'Using SIGKILL', pid
os.kill(pid, signal.SIGKILL)
children = AvnUtils.getInitCfg(host)
AvnUtils.killOrphans(children, host)
def main():
os.chdir(TopDir)
if len(sys.argv) == 1:
killAll()
else:
killServers(sys.argv[1])
if __name__ == '__main__':
main()