我用bottle和python运行了一个API RestFul,一切正常,API是在系统中运行的守护进程,如果我通过命令行停止守护进程,服务停止很好并关闭了所有的端口和连接,但是当我通过API关闭服务时,端口在LISTEN状态下保持活动状态,之后在TIME_WAIT状态下保持活动状态,但不释放端口。我读了两天,但问题是因为瓶子有一个插座,它并没有很好地关闭服务器,但我可以找到他的解决方案Bottle Microframework一旦关闭就不关闭套接字
将API作为服务关闭的代码是由python启动的子进程像这样
@get('/v1.0/services/<id_service>/restart')
def restart_service(id_service):
try:
service = __find_a_specific_service(id_service)
if(service == None or len(service) < 1):
logging.warning("RESTful URI: /v1.0/services/<id_service>/restart " + id_service +" , restart a specific service, service does not exists")
response.status = utils.CODE_404
return utils.convert_to_json(utils.FAILURE, utils.create_failed_resource(utils.WARNING, utils.SERVICES_API_SERVICE_NOT_EXIST))
else:
if id_service != "API":
api.ServiceApi().restart(id_service)
else:
import subprocess
args='/var/lib/stackops-head/bin/apirestd stop; sleep 5; /var/lib/stackops-head/bin/apirestd start'
subprocess.Popen(args, shell=True)
logging.info("RESTful URI: /v1.0/services/<id_service>/restart " + id_service +" , restart a specific service, ready to construct json response...")
return utils.convert_to_json(utils.SERVICE, None)
except Exception, e:
logging.error("Services: Error during the process of restart a specific service. %r", e)
raise HTTPError(code=utils.CODE_500, output=e.message, exception=e, traceback=None, head