Skip to content

Commit

Permalink
Kill ghosts process at startup (Dynamips, VPCS, Ubridge)
Browse files Browse the repository at this point in the history
This is done only if you lock by pid to avoid killing process
of another server.

Fix #581
  • Loading branch information
julien-duponchelle committed Jun 20, 2016
1 parent ae076c7 commit 07395c9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gns3server/run.py
Expand Up @@ -26,6 +26,7 @@
import sys
import locale
import argparse
import psutil
import asyncio

from gns3server.server import Server
Expand Down Expand Up @@ -180,6 +181,21 @@ def pid_lock(path):
sys.exit(1)


def kill_ghosts():
"""
Kill process from previous GNS3 session
"""
detect_process = ["vpcs", "ubridge", "dynamips"]
for proc in psutil.process_iter():
try:
name = proc.name().lower().split(".")[0]
if name in detect_process:
proc.kill()
log.warning("Killed ghost process %s", name)
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass


def run():
args = parse_arguments(sys.argv[1:])

Expand All @@ -189,6 +205,7 @@ def run():

if args.pid:
pid_lock(args.pid)
kill_ghosts()

level = logging.INFO
if args.debug:
Expand Down

0 comments on commit 07395c9

Please sign in to comment.