Post by @mcc@mastodon.social

mcc
@mcc @mastodon.social

I have 2 Linux VPSes running Apache. Over the years, system upgrades have switched everything to systemd out from under me and some of my prior sysadmin knowledge is no longer correct.

I have been having for the last few weeks a problem where apache will simply quit. Nothing in the error.log, nothing that looks relevant in journalctl. No error I've seen. The page isn't loaded, I check, apache is not loaded.

The VPSes are low-resource, so the most obvious conclusion is "OOMkiller did it"

(1/2)

Replying to @mcc@mastodon.social
kasperd
@kasperd @westergaard.social

The kernel log will tell you if that killed anything.

Replying to @mcc@mastodon.social

@mcc if its because of oom, systemctl status $apache should show status: OOMKilled or something along these lines
and if it isnt oom, it will list the last few log lines and the exit code there

mcc
@mcc @mastodon.social

@4censord "status: inactive (dead) since [1h 39min ago]"

First off that's false, second off it gives no hint of the reason for the system death.

Replying to @mcc@mastodon.social
mcc
@mcc @mastodon.social

I discover that for some reason (!?!?!??) OOMkills are not logged in journalctl; they are logged in dmesg. I look in dmesg. I find lots of oomkill messages saying they killed mysql. Not apache, mysql.

I look in the .service files. mysql is Restart=on-failure and apache is Restart=on-abort.

I think what I want to do is change apache to Restart=on-failure. However now I am afraid of "oom fights" where apache and mysql get in a loop of killing each other when they start up.

(2/3)

Replying to @mcc@mastodon.social
mcc
@mcc @mastodon.social

I *think* this is how I avoid "oomkill fights"

redhat.com/en/blog/systemd-aut

But I am wondering if there is any better way to get and view coherent logs/reports about oomkills. I think I could make something like this by writing a python script that scans dmesg at all times and gives me a daily report like "mysql oomkilled 8 times today, apache2 once". It seems like something that might exist already (but if it's vibecoded, I'd rather write the python script myself). (3/3)

Replying to @mcc@mastodon.social
Ken Milmore
@kbm0 @mastodon.social

@mcc It is usual for the systemd journal to include kernel messages, so I was surprised to see you complain that they weren't there. Looking at the docs, it appears that only the journald running in the default namespace collects kernel messages by default, so presumably you only have access to the journal inside the container?

Replying to @mcc@mastodon.social
mcc
@mcc @mastodon.social

Okay. Here's a batshit question. systemctl status apache2.service claims apache is inactive (dead) since 1h39min ago. I have definitely relaunched apache more recently than that. Is it possible sudo apache2ctl graceful somehow does something that breaks systemd's ability to track process health? :( I thought apache2ctl worked through systemd now. (4/3 postscrpit)

Replying to @mcc@mastodon.social
Lou.
@gkrnours @mastodon.gamedev.place

@mcc to my knowledge, systemd trwck health of systemd service, not binary in your system like apache? So if you use apachectl, it bypass systemctl qnd you see what you see.

mcc
@mcc @mastodon.social

@gkrnours That's correct

Replying to @mcc@mastodon.social

@mcc systemd won't track something started separately .. there's an argument that modifies how it tracks the stuff it launches... that I can't recall...

Replying to @mcc@mastodon.social
mcc
@mcc @mastodon.social

Restart=on-failure
StartLimitBurst=3
StartLimitIntervalSec=30

So I think this is what I want for "keep the server from shutting down in transient low-memory situations, but don't keep rebooting if we're in persistent low-memory and the oomkiller gets in a loop". But here's the question:

Is it correct that for Restart=,

on-abort ⊂ on-abnormal ⊂ on-failure

EG, on-failure catches all failure types on-abnormal does and then some, same for on-abnormal vs on-abort?

freedesktop.org/software/syste

Replying to @mcc@mastodon.social
Matthew Miller
@mattdm @hachyderm.io

@mcc

Something weird is happening. These messages normally _are_ in the journal. Maybe your VPS isn't exposing the full logs to you?

Replying to @mcc@mastodon.social
schrotthaufen
@schrotthaufen @mastodon.social

@mcc OOM status should be logged by journald. A quick test gave me: `kernel: Out of memory: Killed process 152726 (tail) …`

Replying to @mcc@mastodon.social
Peter Marheine
@pmarheine @digipres.club

@mcc /proc/vmstat has a line `oom_kills` counting the number of OOM kills since boot.

mcc
@mcc @mastodon.social

@pmarheine OMG thank you so much

$ cat /proc/vmstat | grep oom
oom_kill 99

Hannibel Burress ha ha man this sucks.gif

Replying to @mcc@mastodon.social
Noxie :butterfly_lesbian:
@Noxie @eldritch.cafe

@mcc the zodiac killer would be proud 🥲
@pmarheine

Replying to @mcc@mastodon.social
Lee Leighton
@leel8on @mastodon.social

@mcc @pmarheine 99 problems but a running process ain't one

Replying to @mcc@mastodon.social
fraggLe!
@fwaggle @moodoo.org

@mcc The other things you can do, though how exactly to do it is very opaque and not at all sitting I remember, is influence the oomkiller.

For instance if someone has to get taken out behind the shed, you might consider it better that Apache does than MySQL. So you can alter the knobs (I think they're in /proc directly, but the systemd unit is probably the true place) to ensure that mysqld is unlikely to get aborted.

Note that cgroups/containers interact weirdly with this though.

Replying to @mcc@mastodon.social
Red Rozenglass
@rozenglass @fedi.dreamscape.link
@mcc@mastodon.social Both MySQL and Apache can be configured to limit themselves to less memory usage I think, might allow them to be more conservative and efficient in their internal allocations if they know ahead of time that they have a small amount of heap memory / workers / connections allowed. Perhaps better than processess dying and restarting all the time, but you know your use-case better of course.
mcc
@mcc @mastodon.social

@rozenglass Yes, one thing of note is that I'm running Apache in a low-RAM configuration on VPS A, but I am not doing so on VPS B, although VPS B has less RAM than VPS A. Hm.

Replying to @mcc@mastodon.social
Red Rozenglass
@rozenglass @fedi.dreamscape.link
@mcc@mastodon.social Intentionally? Or an old oversight?
woodland creature
@meowski @fluf.club
@rozenglass @mcc there are tools like this: https://database.gkanev.com/ that can help you optimize mysql memory usage for your system
Replying to @meowski@fluf.club
Red Rozenglass
@rozenglass @fedi.dreamscape.link
@mcc@mastodon.social @meowski@fluf.club
https://database.gkanev.com
Thanks, I'll take a look at that config generator myself~
Replying to @mcc@mastodon.social

@mcc@mastodon.social You might consider looking for cores. Also might consider temporarily turning on verbose logging.

Also systemd has fairly extensive facilities for logging and debugging. It's definitely More Stuff To Learn, but it's been around long enough at this point that between documentation and resources there are lots of good hand/foot holds available.

The trick is to get past that initial "What what WHAT?" feeling and get used to the new plumbing. It's just different. Annoyingly, seemingly pointlessly so in some cases, but totally tractible to come up to speed with given a modicum of effort.

Happy hunting and obv let the fedi hive mind know if you get stuck.

Replying to @feoh
mcc
@mcc @mastodon.social

@feoh "The trick is to get past that initial "What what WHAT?" feeling and get used to the new plumbing"

I guess I have to decide which is more work, that or switching to FreeBSD.

Replying to @mcc@mastodon.social

@mcc@mastodon.social For sure! Although those are different in ... different ways. I'd be lying if I told you that systemd was love at first sight for me, but over time I've actually come to appreciate a number of things about it. Its unit specifications are actually pretty nice, and when push comes to shove and it's "OK I want to run this as a daemon with the following attributes" time, it's all pretty reasonable.

But FreeBSD and Illumos seem pretty groovy too! No bad choices!

I really need to get one of those running in a VM just to kick the tires.