Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -N args, but script not work, how to fix it? #323

Open
axiaoxin opened this issue Aug 6, 2024 · 1 comment
Open

Add -N args, but script not work, how to fix it? #323

axiaoxin opened this issue Aug 6, 2024 · 1 comment

Comments

@axiaoxin
Copy link

axiaoxin commented Aug 6, 2024

8月 06 05:17:09  earlyoom[1668157]: mem avail:  1506 of  6888 MiB (21.86%), swap free:    0 of    0 MiB ( 0.00%)
8月 06 05:23:41  earlyoom[1668157]: mem avail:   692 of  6947 MiB ( 9.96%), swap free:    0 of    0 MiB ( 0.00%)
8月 06 05:23:41  earlyoom[1668157]: low memory! at or below SIGTERM limits: mem 10.00%, swap 10.00%
8月 06 05:23:41 earlyoom[1668157]: sending SIGTERM to process 1965702 uid 0 "Isolated Web Co": oom_score 850, VmRSS 1308 MiB, cmdline "/root/.cache/selenium/firefox/linux64/128.0.3/firefox-bin -contentproc -childI>
8月 06 05:23:41 earlyoom[1668157]: kill_release: pid=1965702: process_mrelease pidfd=4 success
8月 06 05:23:41 earlyoom[1668157]: process 1965702 exited after 0.000 seconds

no logs for scripts.

the script code:

#!/bin/bash

WEBHOOK_URL='https://qyapi.weixin.qq.com/cgi-bin/webhook/send'

CONTENT="earlyoom killed\n\n"
CONTENT+="PID: $EARLYOOM_PID\n"
CONTENT+="NAME: $EARLYOOM_NAME\n"
CONTENT+="CMD: $EARLYOOM_CMDLINE\n"
CONTENT+="UID: $EARLYOOM_UID"

curl -X POST "$WEBHOOK_URL" \
     -H "Content-Type: application/json" \
     -d "{
           \"msgtype\": \"text\",
           \"text\": {
               \"content\": \"$CONTENT\"
           }
     }"

config:

EARLYOOM_ARGS="-r 600 -m 10 -s 10 -N /etc/notifer/script.sh --avoid '(^|/)(init|sshd)$'"

May I ask if this is correct for me? How to check if a script runs when a process is killed, how to view script run logs or check error messages?Thanks!

@miraculixx
Copy link

miraculixx commented Nov 7, 2024

I had a similar problem, except for the desktop notifications. Since I couldn't get -N to work, I created this script, /home/user/.local/bin/syslog-check.sh:

#!/bin/bash
REGEX_PATTERN="$1"
SINCE_TIME="$(date --date='15 seconds ago' '+%Y-%m-%d %H:%M:%S')"
export DISPLAY=:0
journalctl --since="$SINCE_TIME" --quiet | grep -v $0 | grep --line-buffered -E "$REGEX_PATTERN" | while read -r line; do
    notify-send "journal" "$line"
done

Then I run it using crontab

$ crontab -e
# check for earlyoom syslog messages and send desktop notification every 15 seconds
* * * * * /home/user/.local/bin/syslog-check.sh "earlyoom.*SIG" 15 >/dev/null 2>&1
* * * * * (sleep 15; /home/user/.local/bin/syslog-check.sh "earlyoom.*SIG" 15) >/dev/null 2>&1
* * * * * (sleep 30; /home/user/.local/bin/syslog-check.sh "earlyoom.*SIG" 15) >/dev/null 2>&1
* * * * * (sleep 45; /home/user/.local/bin/syslog-check.sh "earlyoom.*SIG" 15) >/dev/null 2>&1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants