ajout de l'envoie de l'ordre de fermeture de l'appli intercom en cas de reboot ou poweroff
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
import sys, re, os
|
||||
import logging as log
|
||||
from datetime import datetime, timezone
|
||||
import time
|
||||
|
||||
from flask import Flask, Blueprint, request, abort, jsonify, current_app
|
||||
from flask_api import status
|
||||
@@ -25,6 +26,8 @@ import hashlib
|
||||
import subprocess
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
from ConfBack.manager import Sock
|
||||
|
||||
#########################################################
|
||||
# Class et Methods #
|
||||
|
||||
@@ -166,6 +169,18 @@ def reboot():
|
||||
if os.path.exists(userpath):
|
||||
shutil.rmtree(userpath)
|
||||
|
||||
conn = Sock(addr=current_app.config['UNIX_ADDR'], logger=current_app.logger)
|
||||
if not conn.connect():
|
||||
current_app.logger.error("impossible de se connecter au serveur")
|
||||
else:
|
||||
# send order to KineIntercom process
|
||||
if not conn.send(b"SHUTDOWN\n"):
|
||||
conn.disconnect()
|
||||
current_app.logger.error("impossible de communiquer avec le serveur")
|
||||
|
||||
conn.disconnect()
|
||||
time.sleep(3)
|
||||
|
||||
reboot_cmd = ['sudo', '/bin/systemctl', 'reboot']
|
||||
if not execute_cmd(reboot_cmd):
|
||||
abort(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
@@ -186,6 +201,18 @@ def shutdown():
|
||||
if os.path.exists(userpath):
|
||||
shutil.rmtree(userpath)
|
||||
|
||||
conn = Sock(addr=current_app.config['UNIX_ADDR'], logger=current_app.logger)
|
||||
if not conn.connect():
|
||||
current_app.logger.error("impossible de se connecter au serveur")
|
||||
else:
|
||||
# send order to KineIntercom process
|
||||
if not conn.send(b"SHUTDOWN\n"):
|
||||
conn.disconnect()
|
||||
current_app.logger.error("impossible de communiquer avec le serveur")
|
||||
|
||||
conn.disconnect()
|
||||
time.sleep(3)
|
||||
|
||||
reboot_cmd = ['sudo', '/bin/systemctl', 'poweroff']
|
||||
if not execute_cmd(reboot_cmd):
|
||||
abort(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user