Skip to content

Commit

Permalink
Add cic-monitor service to monitor shutdown events.
Browse files Browse the repository at this point in the history
Change-Id: Ice57f6a87441468a01f9ea1ad58b8ab191ec71c4
Tracked-On: OAM-89821
Signed-off-by: bxu10x <[email protected]>
  • Loading branch information
xubing676 committed Apr 7, 2020
1 parent 97f3caf commit 68f21a2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
61 changes: 61 additions & 0 deletions cic_dev/addon/pre-requisites/cic-monitor-service
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions cic_dev/addon/setup-aic
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 68f21a2

Please sign in to comment.