Skip to content

Commit 220c2f6

Browse files
committed
[core] New o2-aliecs-shmcleaner script + Makefile for it
1 parent d0fc109 commit 220c2f6

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,26 @@ $(WHAT):
8787
# @echo ${PWD}
8888
@$(WHAT_$@_BUILD_FLAGS) go build -mod=vendor $(VERBOSE_$(V)) -o bin/$@ $(LDFLAGS) ./cmd/$@
8989

90+
# special case: if the current WHAT is o2-aliecs-executor, also copy over the shmcleaner script
91+
@if [ $@ == "o2-aliecs-executor" ]; then \
92+
echo -e "\033[1;33mcopy\033[0m ./cmd/o2-aliecs-shmcleaner \033[1;33m==>\033[0m \033[1;34m./bin/o2-aliecs-shmcleaner\033[0m"; \
93+
cp cmd/o2-aliecs-shmcleaner bin/o2-aliecs-shmcleaner; \
94+
chmod +x bin/o2-aliecs-shmcleaner; \
95+
fi; \
96+
9097
$(INSTALL_WHAT):
9198
# @echo -e "WHAT_$(@:install_%=%)_BUILD_FLAGS $(WHAT_$(@:install_%=%)_BUILD_FLAGS)"
9299
@echo -e "\033[1;33mgo install -mod=vendor\033[0m ./cmd/$(@:install_%=%) \033[1;33m==>\033[0m \033[1;34m$$GOPATH/bin/$(@:install_%=%)\033[0m"
93100
# @echo ${PWD}
94101
@$(WHAT_$(@:install_%=%)_BUILD_FLAGS) go install -mod=vendor $(VERBOSE_$(V)) $(LDFLAGS) ./cmd/$(@:install_%=%)
95102

103+
# special case: if the current WHAT is o2-aliecs-executor, also copy over the shmcleaner script
104+
@if [ $@ == "install_o2-aliecs-executor" ]; then \
105+
echo -e "\033[1;33minstall\033[0m ./cmd/o2-aliecs-shmcleaner \033[1;33m==>\033[0m \033[1;34m$$GOPATH/bin/o2-aliecs-shmcleaner\033[0m"; \
106+
cp cmd/o2-aliecs-shmcleaner $${GOPATH}/bin/o2-aliecs-shmcleaner; \
107+
chmod +x $${GOPATH}/bin/o2-aliecs-shmcleaner; \
108+
fi; \
109+
96110
generate:
97111
ifndef HAS_PROTOC
98112
$(MAKE) tools/protoc

cmd/o2-aliecs-shmcleaner

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# === This file is part of ALICE O² ===
4+
#
5+
# Copyright 2021 CERN and copyright holders of ALICE O².
6+
# Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
7+
#
8+
# Partially derived from Torus Makefile <https://github.com/coreos/torus>
9+
#
10+
# This program is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, either version 3 of the License, or
13+
# (at your option) any later version.
14+
#
15+
# This program is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
#
23+
# In applying this license CERN does not waive the privileges and
24+
# immunities granted to it by virtue of its status as an
25+
# Intergovernmental Organization or submit itself to any jurisdiction.
26+
27+
O2_INFOLOGGER_PATH=/opt/o2-InfoLogger
28+
export O2_SYSTEM=ECS
29+
export O2_FACILITY=core/shmcleaner
30+
export O2_PARTITION=${O2_PARTITION:-}
31+
export O2_ROLE=${O2_ROLE:-}
32+
33+
ANY_FILES_CLEANED=false
34+
35+
for SHM_FILE in /dev/shm/*; do
36+
if [ -f $SHM_FILE ] ; then
37+
SIZE=$(ls -lah $SHM_FILE | awk -F " " {'print $5'})
38+
if ! fuser -s $SHM_FILE ; then
39+
rm -f $SHM_FILE
40+
echo "freed unused shared memory $SHM_FILE ($SIZE)" | $O2_INFOLOGGER_PATH/bin/o2-infologger-log -x -s Debug -o Facility=$O2_FACILITY
41+
ANY_FILES_CLEANED=true
42+
else
43+
echo "could not free shared memory in use $SHM_FILE ($SIZE)" | $O2_INFOLOGGER_PATH/bin/o2-infologger-log -x -s Warning -o Facility=$O2_FACILITY
44+
fi
45+
fi
46+
done
47+
48+
if [ "$ANY_FILES_CLEANED" = false ] ; then
49+
echo "no shared memory freed" | $O2_INFOLOGGER_PATH/bin/o2-infologger-log -x -s Debug -o Facility=$O2_FACILITY
50+
fi

0 commit comments

Comments
 (0)