Wanted: Email notification on reboot

SYSTEM INFORMATION
OS type and version Raspbian Linux 11
Webmin version 2.104

I suspect this is quite simple, but I can’t figure it out. I’d like Webmin to send me an email notification if/when the system reboots (e.g. following a power failure). I have email configured properly, and Webmin successfully sends emails when Package Updates are available. I just can’t figure out how to configure a monitor within the System and Server Status tool that will send an email when the system restarts.

System and Server Status -> Add Monitor of Type = Bootup Action
then complete the form.
Don’t forget to click “Create”

Thanks for that. But I’m still not seeing any emails. I selected the default ‘Action to check – ModemManager.service’ because that seemed as good a service to check on reboot as any and it does get started automatically when the system boots. I tried ‘No’ for ‘Check on schedule’ because I want the email only when the reboot happens, not on some schedule. When that didn’t result in any email, I selected ‘Yes, and report on status changes’ and enabled Scheduled Monitoring but received no email for that either. I have no idea if I should enter any commands to run, so I entered none. Clearly, there’s something on the Edit Monitor for Bootup Action page that I have omitted or entered incorrectly, but I don’t know what. What am I missing?

Did it even run? See Status history - No need to schedule it should run continuous.

Is the Bootup Action now listed under System and Server Status
It should also have a green tick against it - see example:

Over a period of an hour or so, I tried both ‘No’ and ‘Scheduled’ but the monitor doesn’t seem to run unless I enable Scheduled Monitoring, when it runs every 5 minutes. Even when it DOES run, it fails to see a change in status because the service is always running – Webmin never sees the service when it’s down.

The best thing to do is add a cron job that runs at reboot rather than using system monitor. Just do a a script that echos the message you want and make sure the mailto environment variable is set to the email address you want

I don’t understand - mine is working just fine - no schedule. The only thing different is that I have a notification outside the server (but that shouldn’t be an issue)

Thanks @jimr1. Here’s what I have working now:

It’s a File Change monitor. I’ve added a cron job:
@reboot sleep 60 && touch ~/Reboot.txt

The 60-second delay is intended to allow the reboot to fully complete before triggering the File Change. Not sure it’s really necessary.

The only ‘flaw’ in this implementation is that the monitor status simply toggles with each reboot as you can see in the Status History. The up/down state reported by the monitor simply reflects the change in state. Still fiddling, and it seems like it should be easier. But this is working.

@Stegan, I agree. Like so many things, it should work. See my reply to @jimr.

For me it does work though. So I am wondering if there is some other difference in in system

My OS is Ubuntu 20.04, my Webmin version is 2.101 my theme is Authentic theme 21.09.4

I’m running on Raspbery Pi OS Debian 11 with Webmin 2.104. So the executable for the Raspberry ARMHF may indeed be somewhat different. I notice that on a plain Debian 11 box, running 2.104 that Edit Monitor page contains a ‘Template for messages’ box that is not available on the Raspberry Pi. I use the Framed theme.

Bootup Action does not do what you think it does. It is not checking for a system boot, it is checking the status of a given service (ModemManager.service in your case), which can change state in a variety of circumstances, not just during a system boot, and I’m not at all confident that it would trigger on a reboot. See “System->Bootup and Shutdown” for the services this action can monitor (and it relies on the OS init system to tell it whether it’s up or down).

I have my doubts about this being a reliable method of detecting a reboot, because Webmin and the status monitoring job may not start until after the service you’ve chosen to trigger on, so it may miss a state change. And, of course, since the service (the “bootup action”) can be stopped or started outside of a reboot, it is also likely to give false positives.

I think this is probably a poor name for this alert type, as I can see how you could be led to believe it is about a system boot. Jamie named it after Bootup and Shutdown, which is named the way it is because it covers a bunch of different init systems (which handle how the system boots and shuts down) with different names and terminology.

I wouldn’t do this with a Webmin System and Server Status monitor (which is intended to show state changes, and also starts relatively late in the boot process, so it’ll miss a lot of state changes that happen during boot). I’d probably just write a systemd service that runs a script that sends email when it starts.

If you did want it to be a Webmin service, I guess I’d write a script that checks last reboot|head -1 to see if the time/date has changed since the last check (stored in a file), and write the new time/date to the file if it has, and run that script with the Execute Command monitor type. Have it return 0 (true in shell scripts) if one condition is true (e.g. if the last boot time changed) and 1 (false in shell scripts) on the other. I’ll leave writing that script as an exercise for the reader.

It’s a lot less code to write a systemd service to email on boot, though, since sending email is usually just one command…can probably even be the ExecStart with no script needed. e.g. ExecStart=mail -s 'System booted' joe@domain.tld. I haven’t tested this, but I can’t think of why it wouldn’t just work. The simplest systemd service file is only a half dozen lines long, all declarative.

Some systems will have a /var/log/boot.log or maybe some others that change state only on reboot (which can be checked with a File or Directory Change monitor), but I think that’s probably going away as the journal catches more and more logs.

Add a new cronjob, one line, eg.

@reboot root mail -s “server.name just rebooted” your@mail.tld

2 Likes

Ooh! I didn’t know about the @reboot magic variable. That’s neat. Yeah, I think that’s the easiest option.

@Joe thanks for that explanation.

The odd think is that it is (has) been working here. So potentially there have been reboots that have been missed due to the check being late in sequence.

I agree the name is misleading.

@Randomz that is a great one liner I’ll replace the existing bootup check with that. Tx

Thanks all, especially @Joe, for the excellent explanation. But I don’t use Linux mail. Nor have I configured an MTA. I configure Webmin to send to my gmail address so I don’t have to logon to the device to check Linux mail. So, for now at least, I’m sticking to the File or Directory Change monitor that I described in the post that I marked as the solution. It works for me.

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.