bare-metal: hostlogger: restrict hostlogger to guestOS only
This will delay starting the hostlogger in baremetal mode. It will
start/stop with the gbmc-bare-metal-active.target.
Tested:
# In a simulation of BM mode:
echo anything > /dev/tty0
root@dddgj26-nfd01:~# wget -qO - http://localhost/redfish/v1/Systems/system/LogServices/HostLogger/Entries
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries",
"@odata.type": "#LogEntryCollection.LogEntryCollection",
"Description": "Collection of HostLogger Entries",
"Members": [],
"Members@odata.count": 0,
"Name": "HostLogger Entries"
root@dddgj26-nfd01:~# systemctl start gbmc-bare-metal-active.target
root@dddgj26:~# echo hello > /dev/tty0
root@dddgj26-nfd01:~# wget -qO - http://localhost/redfish/v1/Systems/system/LogServices/HostLogger/Entries
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries",
"@odata.type": "#LogEntryCollection.LogEntryCollection",
"Description": "Collection of HostLogger Entries",
"Members": [
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/0",
"@odata.type": "#LogEntry.v1_9_0.LogEntry",
"EntryType": "Oem",
"Id": "0",
"Message": "hello",
"Name": "Host Logger Entry",
"OemRecordFormat": "Host Logger Entry",
"Severity": "OK"
},
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/1",
"@odata.type": "#LogEntry.v1_9_0.LogEntry",
"EntryType": "Oem",
"Id": "1",
"Message": "\n",
"Name": "Host Logger Entry",
"OemRecordFormat": "Host Logger Entry",
"Severity": "OK"
}
],
"Members@odata.count": 2,
"Name": "HostLogger Entries"
root@dddgj26-nfd01:~# systemctl stop gbmc-bare-metal-active.targets
dddgj26:~# echo hello2 > /dev/tty0
root@dddgj26-nfd01:~# wget -qO - http://localhost/redfish/v1/Systems/system/LogServices/HostLogger/Entries
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries",
"@odata.type": "#LogEntryCollection.LogEntryCollection",
"Description": "Collection of HostLogger Entries",
"Members": [
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/0",
"@odata.type": "#LogEntry.v1_9_0.LogEntry",
"EntryType": "Oem",
"Id": "0",
"Message": "hello",
"Name": "Host Logger Entry",
"OemRecordFormat": "Host Logger Entry",
"Severity": "OK"
},
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/1",
"@odata.type": "#LogEntry.v1_9_0.LogEntry",
"EntryType": "Oem",
"Id": "1",
"Message": "\n",
"Name": "Host Logger Entry",
"OemRecordFormat": "Host Logger Entry",
"Severity": "OK"
}
],
"Members@odata.count": 2,
"Name": "HostLogger Entries"
root@dddgj26-nfd01:~# systemctl restart gbmc-bare-metal-active.target
dddgj26:~# echo hello_restart > /dev/tty0
root@dddgj26-nfd01:~# wget -qO - http://localhost/redfish/v1/Systems/system/LogServices/HostLogger/Entries
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries",
"@odata.type": "#LogEntryCollection.LogEntryCollection",
"Description": "Collection of HostLogger Entries",
"Members": [
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/0",
"@odata.type": "#LogEntry.v1_9_0.LogEntry",
"EntryType": "Oem",
"Id": "0",
"Message": "hello",
"Name": "Host Logger Entry",
"OemRecordFormat": "Host Logger Entry",
"Severity": "OK"
},
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/1",
"@odata.type": "#LogEntry.v1_9_0.LogEntry",
"EntryType": "Oem",
"Id": "1",
"Message": "\n",
"Name": "Host Logger Entry",
"OemRecordFormat": "Host Logger Entry",
"Severity": "OK"
},
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/2",
"@odata.type": "#LogEntry.v1_9_0.LogEntry",
"EntryType": "Oem",
"Id": "2",
"Message": "hello_restart",
"Name": "Host Logger Entry",
"OemRecordFormat": "Host Logger Entry",
"Severity": "OK"
},
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/3",
"@odata.type": "#LogEntry.v1_9_0.LogEntry",
"EntryType": "Oem",
"Id": "3",
"Message": "\n",
"Name": "Host Logger Entry",
"OemRecordFormat": "Host Logger Entry",
"Severity": "OK"
}
],
"Members@odata.count": 4,
"Name": "HostLogger Entries"
https://fusion2.corp.google.com/ci/guitar/projects/UNSPECIFIED/activity/227979c0-0603-4884-b477-4e7de5cce600/overview
Note: above fution link is from cherry pick. For release branch there is an ongoing issue that blocks all presubmits. We manually verified that nightly result looks good and all tests in presubmit passed.
Google-Bug-Id: 316190388
Change-Id: Ie5c3632345d5ebad88fc419caff94679c2df0fa2
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
(cherry picked from commit ff64d40ba246b5861557b18eeb706eab27eb2c2d)
diff --git a/recipes-google/bare-metal-setup/files/bare-metal-setup.sh.in b/recipes-google/bare-metal-setup/files/bare-metal-setup.sh.in
index 8c31d24..f29e5fb 100644
--- a/recipes-google/bare-metal-setup/files/bare-metal-setup.sh.in
+++ b/recipes-google/bare-metal-setup/files/bare-metal-setup.sh.in
@@ -48,6 +48,49 @@
}
+function override_hostlogger_in_bm_mode() {
+ systemd_runtime_dir='/run/systemd/system'
+ hostlogger_service="hostlogger@.service"
+ hostlogger_override_dir="${systemd_runtime_dir}/${hostlogger_service}.d"
+
+ mkdir -p ${hostlogger_override_dir}
+ echo "[Unit]
+BindsTo=gbmc-bare-metal-active.target
+Before=gbmc-bare-metal-active.target
+[Install]
+WantedBy=
+WantedBy=gbmc-bare-metal-active.target
+" > "${hostlogger_override_dir}/50-bm-override.conf"
+
+ # Overriding Install section does not work for already installed service
+ # Moving the service directly and recover it when turning off BM mode.
+ # mv seems not happy with jffs + symlink.
+
+ systemd_etc_dir='/etc/systemd/system'
+
+ mkdir -p ${systemd_etc_dir}/gbmc-bare-metal-active.target.wants
+
+ cp -P ${systemd_etc_dir}/multi-user.target.wants/hostlogger@*.service \
+ ${systemd_etc_dir}/gbmc-bare-metal-active.target.wants/
+
+ rm ${systemd_etc_dir}/multi-user.target.wants/hostlogger@*.service
+
+ # looks like we need to stop from any existing transaction to really prevent
+ # it from starting
+ systemctl stop hostlogger@*.service
+}
+
+function recover_hostlogger_in_bm_mode() {
+ systemd_etc_dir='/etc/systemd/system'
+
+ mkdir -p ${systemd_etc_dir}/multi-user.target.wants
+
+ cp -P ${systemd_etc_dir}/gbmc-bare-metal-active.target.wants/hostlogger@*.service \
+ ${systemd_etc_dir}/multi-user.target.wants/ 2> /dev/null
+
+ rm ${systemd_etc_dir}/gbmc-bare-metal-active.target.wants/hostlogger@*.service 2> /dev/null
+}
+
function hide_boot_drive_in_bm_mode() {
# In Bare Metal mode, power off the boot drive
if [[ "$BM_MODE" -eq "1" || -f "$ENABLE_BM_FILE" ]]; then
@@ -63,6 +106,7 @@
# Change the host console to read only, unless we require to keep the
# console
if [[ ! -f "$ENABLE_CONSOLE_FILE" ]]; then
+ override_hostlogger_in_bm_mode
override_obmc_console_in_bm_mode
fi
@@ -71,6 +115,7 @@
else
# Mask services that could disable ipmi
ln -s /dev/null /run/systemd/system/host-gpio-monitor.service 2> /dev/null
+ recover_hostlogger_in_bm_mode
systemctl daemon-reload
# Turn on the power to the boot drive