-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
earlyoom: Add vlab-earlyoom-static and update notify script
- Loading branch information
Showing
9 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Package: vlab-earlyoom-static | ||
Version: 1.1-5 | ||
Section: base | ||
Priority: optional | ||
Architecture: amd64 | ||
Recommends: zenity | ||
Provides: earlyoom | ||
Conflicts: earlyoom, vlab-earlyoom | ||
Replaces: earlyoom, vlab-earlyoom | ||
Maintainer: USTC Vlab <[email protected]> | ||
Description: Vlab earlyoom configurations for interactive responsiveness, with static earlyoom binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
echo "Enabling and starting vlab-earlyoom.service..." | ||
systemctl enable --now vlab-earlyoom.service || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
PACKAGE=vlab-earlyoom | ||
|
||
case "$1" in | ||
install) | ||
systemctl unmask earlyoom.service || true | ||
;; | ||
upgrade|abort-upgrade) | ||
systemctl unmask earlyoom.service || true | ||
;; | ||
*) | ||
echo "preinst called with unknown argument \`$1'" >&2 | ||
exit 0 | ||
;; | ||
esac | ||
#DEBHELPER# | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Options to pass to earlyoom | ||
EARLYOOM_ARGS="-r 60 -m 5,4 -s 5 --avoid sshd -N /etc/vlab/earlyoom-notif.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
MSG="由于内存不足,earlyoom 已结束进程 $EARLYOOM_NAME 以保证用户界面流畅。如果多次看到此消息,请联系管理员添加内存。" | ||
|
||
RATELIMIT="/tmp/earlyoom-ratelimit" | ||
|
||
( | ||
flock -x 200 -w 2 | ||
if [ -f "$RATELIMIT" ]; then | ||
CURRENT=$(date +%s) | ||
FILE=$(stat -c %Y "$RATELIMIT") | ||
|
||
DIFF=$((CURRENT-FILE)) | ||
# 10 seconds rate-limit | ||
if [ "$DIFF" -lt 10 ]; then | ||
echo "Rate-limited earlyoom notification" | ||
exit 0 | ||
fi | ||
fi | ||
touch "$RATELIMIT" | ||
) 200>"$RATELIMIT" | ||
|
||
wall "$MSG" | ||
date >> /tmp/earlyoom-record | ||
if ! command -v zenity &> /dev/null; then | ||
exit 0 | ||
fi | ||
|
||
if id "ubuntu" &>/dev/null; then | ||
USER="ubuntu" | ||
else | ||
USER="vlab" | ||
fi | ||
|
||
DISPLAY=:0 sudo -u "$USER" zenity --error --text "$MSG" & |
17 changes: 17 additions & 0 deletions
17
vlab-earlyoom-static/lib/systemd/system/vlab-earlyoom.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=Early OOM Daemon in Vlab environment | ||
Documentation=man:earlyoom(1) https://github.com/rfjakob/earlyoom | ||
|
||
[Service] | ||
EnvironmentFile=-/etc/default/earlyoom | ||
ExecStart=/usr/bin/earlyoom $EARLYOOM_ARGS | ||
# earlyoom never exits on it's own, so have systemd | ||
# restart it should it get killed for some reason. | ||
Restart=always | ||
# set memory limits and max tasks number | ||
TasksMax=10 | ||
MemoryMax=50M | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
Alias=earlyoom.service |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
Package: vlab-earlyoom | ||
Version: 1.1-4 | ||
Version: 1.1-5 | ||
Section: base | ||
Priority: optional | ||
Architecture: all | ||
Recommends: zenity | ||
Provides: earlyoom | ||
Conflicts: earlyoom | ||
Replaces: earlyoom | ||
Conflicts: earlyoom, vlab-earlyoom-static | ||
Replaces: earlyoom, vlab-earlyoom-static | ||
Maintainer: USTC Vlab <[email protected]> | ||
Description: Vlab earlyoom configurations for interactive responsiveness |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters