misc: life_mngr: refine script to trigger system shutdown request

Provide a script to user to trigger system shutdown request
in service VM or user VM.
System shutdown logic have been integrated in the lifecycle
manager, only need to send system shutdown request command
through unix domain socket in this script.

v3-->v4:
	Rewirte system shutdown trigger script using python
	since phython script have better portability.
v4-->v5:
	Update command name and copyright header.

Tracked-On: #6652

Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com>
Reviewed-by: fei1.li@intel.com
This commit is contained in:
Xiangyang Wu
2021-10-19 10:37:43 +08:00
committed by wenlingz
parent 070896dd76
commit 3de9728432
2 changed files with 31 additions and 216 deletions

View File

@@ -0,0 +1,31 @@
#!/usr/bin/env python3
#
# Copyright (C) 2021 Intel Corporation.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import socket
class SocketClient:
def __init__(self):
pass
def connect_to_server(self):
SOKET_ADDR = '/var/lib/life_mngr/monitor.sock'
SHUTDOWN_REQ = 'req_sys_shutdown'
BUF_LEN = 1024
# unix domain sockets
server_address = SOKET_ADDR
socket_family = socket.AF_UNIX
socket_type = socket.SOCK_STREAM
sock = socket.socket(socket_family, socket_type)
sock.connect(server_address)
sock.sendall(SHUTDOWN_REQ.encode())
data = sock.recv(BUF_LEN)
print(f"Waiting for ACK message...: {data.decode()}")
sock.close()
if __name__ == "__main__":
socket_client_obj = SocketClient()
socket_client_obj.connect_to_server()