diff --git a/cic_dev/addon/pre-requisites/cic-monitor-service b/cic_dev/addon/pre-requisites/cic-monitor-service new file mode 100755 index 0000000..51aed6f --- /dev/null +++ b/cic_dev/addon/pre-requisites/cic-monitor-service @@ -0,0 +1,61 @@ +#!/bin/sh + +sudo touch /lib/systemd/system/cic-monitor.service + +echo "Adding CIC Monitor Service" +cat << EOF | sudo tee /lib/systemd/system/cic-monitor.service +[Unit] +Description="Start CIC Monitor service" + +[Service] +WorkingDirectory=/AIC_WORK_DIR/ +Type=oneshot +ExecStart=/usr/bin/python3 /lib/systemd/system/docker-events.py +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target +EOF + +sudo sed -i "s|/AIC_WORK_DIR|$AIC_WORK_DIR|g" /lib/systemd/system/cic-monitor.service + +sudo touch /lib/systemd/system/docker-events.py +echo "Adding event handling file" +cat << EOF | sudo tee /lib/systemd/system/docker-events.py +import subprocess as sp +import json +import os + +def handle(event): + kind, action = event["Type"], event["Action"] + if kind == "container" and action == "die": + name, code = [event["Actor"]["Attributes"][x] + for x in ["name", "exitCode"]] + if code == '129': + print("container {name} exit for reboot") + #os.system('./aic stop') + #on demand + #os.system('reboot') + elif code == '130': + print("container {name} exit for shutdown") + os.system('./aic stop') + #on demand + #os.system('shutdown -h now') + else: + print("container {name} exit {code}") + else: + pass # print(str(event)) + + +def main(): + cmd = ["docker", "events", "--format", r"{{json .}}"] + p = sp.Popen(cmd, stdout=sp.PIPE, universal_newlines=True) + for line in p.stdout: + handle(json.loads(line)) + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + exit(0) +EOF diff --git a/cic_dev/addon/setup-aic b/cic_dev/addon/setup-aic index cb6b3df..2541f22 100755 --- a/cic_dev/addon/setup-aic +++ b/cic_dev/addon/setup-aic @@ -9,6 +9,7 @@ export AIC_WORK_DIR=${PWD} #Initiate Early-Launch #./pre-requisites/launch-early ./pre-requisites/cic-service +./pre-requisites/cic-monitor-service #customize android (add/remove apps etc.) ./pre-requisites/customize-android @@ -61,6 +62,7 @@ sudo chmod 777 -R $AIC_WORK_DIR_PATH sudo chmod 0644 $AIC_WORK_DIR_PATH/data0/local.prop sudo systemctl enable cic +sudo systemctl enable cic-monitor #Run pactl ./pre-requisites/pactl_socket $(whoami)