Sleep & Wake Up

Hi,

I am wondering, if it is possible to make a freebsd server fall asleep like when you close the display of a laptop making the machine switching into stand-by.

On the other hand, is it possible to resume a freebsd server using WoL (wake on lan)?

Does anyone have experience?
 
Add this to /etc/devd.conf:

Code:
notify 10 {
match "system" "ACPI";
match "subsystem" "Lid";
action "/etc/myscript $notify";
};

According to devd.conf(), $notify=0x00 means closed, $notify=0x01 is open.

Don't forget to kill and restart devd, so that it reads the config file anew.

In your script, you can make your server fall asleep (zzz).

Not sure how wake on lan is implemented.
 
Hey George,

thank you, but maybe I was comparing the stand-by state too visual: I meant: "What is the command to make the server to switch to stand-by?"
The answer would actually be the content of /etc/myscript. Sorry, my bad. :what:

All my servers are headless. So there is no lid to close. ;)
I mean it would be funny when you trigger your data center to shut down or switch into stand-by mode when you close the lid of the toilet in the office. Or: If you implement your boss' toilet lid to shut down the data center. Of course, opening the lid should send a WOL-ping to all systems ...

I was kiddin' - ok, no jokes, no off-topic jokes. ?

Being more precisely:
The event that triggers the server to go in stand-by is supposed to be
  • a certain number of specific processes (in this case: list of zero jails)
  • and 100% idle like 1 minute or so.
In other words: if no jail is running and the system is idling more than 60 seconds then switch to stand-by.
How to sense such event and what is the stand-by command?
 
Regarding the certain number of specific processes: It will be a grep on ps piped into wc (word count) comparing eq 0 by using if.

What about the idle couter?

And how to run that check? 1-minute-cron-job?
 
Ok, run a cron job.
I use zzz().
I apologize. I thought you were making jokes by saying:
In your script, you can make your server fall asleep (zzz).
I didn't know zzz is an app. ? I thought about this picture "?"

How ever, George, thank you again.
Regarding executing zzz command there are still missing both mentioned conditions before running zzz as well as the sensing for that condition.

I mean I could do something like this:

Bash:
#!what-ever-shell
// pseudo coded draft
idletime=0
while true do
  check if idle=100%-99% do idletime++ else idletime=0
  check if jails=0 and idletime>=60 do
    zzz // server go to bed
  done
  delay 1 second
done

But this is ?

Rather run this draft by cron(?) every second :

Bash:
#!what-ever-shell
// pseudo coded draft
check if idle=100%-99% do set env-idletime++ else set env-idletime=0
check if jails=0 and env-idletime>=60 do
    zzz // server go to bed
done
 
Is there any mechanism that senses for specific number of some specific process?

Or can I just tell devd to run my script after 60 seconds of being idle? Then the script could count the number auf jails. If the number auf jails is zero then run zzz.
 
If you want to test each second, then the simplest way is to create two Cron job IMHO.

One put the last date if no idle in /tmp/lastNoIdleTime each second.
The second that run zzz if the file does not exist or if now - date > 60.
But there is maybe a simpler way.
 
If you want to test each second, then the simplest way is to create two Cron job IMHO.

One put the last date if no idle in /tmp/lastNoIdleTime each second.
The second that run zzz if the file does not exist or if now - date > 60.
But there is maybe a simpler way.
What about exporting the value to environment variable?
 
I am not sure that two cron jobs shares env vars. To be tested ?
Cron jobs are being executed as same user (root), so they should be able to read globally exported env vars of root, right? I didn't try it before, too. It might be a security issue if it is possible ... :-/ On the other hand, there should be an initial export of some env var to set the value like on login by bash due to .bashrc, I think. So, if you just boot up a system there should be no env var available until root logs in, except you set export command in crontab, if there is no environmental isolation. Logical, but sounds like an stupid idea ... Let's give it a try ... ?

but ...

on the other hand, what if you go
Code:
. script1.sh
. script2.sh
in crontab? :-/
 
The uptime command has the last minute load average. This is maybe sufficient and more elegant to know if the system is on charge or not ?
 
Ok, so the idle issue might be cleared by uptime with a load threshold regarding sensing the load for last 60 seconds. But how to combine uptime with devd? There is no check on load in devd ... :-/

time2sleep.sh
Code:
// pseudo code

on cpu.event "idle" do // event by devd?
  if 0 <= uptime.load <= 0.3 and numberOf.jails == 0 do
    zzz // good night
  done
done

Maybe it is possible to use powerd to execute the command, even though the purpose of powerd is different ... ;)

powerd():
-v Verbose mode. Messages about power changes will be printed to stdout and powerd will operate in the foreground.

check.sh
Code:
// pseudo code

if (grep idle stdin) do
  if 0 <= uptime.load <= 0.3 and numberOf.jails == 0 do
    zzz // good night
  done
done

But this sounds like a stupid idea ... even if you somehow pipe powerd's output thru the check
powerd -v | ./check.sh

Or rather sense on logs, if powerd logs anything !? :-/
 
You should probably test zzz and WOL by hand on your server to make sure they work before scripting anything.

After that, write the simplest possible script that might work, which will be something like the first script you wrote with the sleep in it. You will likely have to poll to get the jail count and CPU usage, and if you're polling anyway, there's nothing wrong with using sleep.

After you get the script working, start it using cron at boot time or run it as a service. Let it run for a while and then make improvements if needed.
 
Maybe top, vmstat or iostat?
Bash:
$ top -Sb | sed -Enr 's/^CPU: .+ (.+)% idle/\1/p'
70.5
$ vmstat | awk 'NR==3 {print $(NF)}'
71
$ iostat | awk 'NR==3 {print $(NF)}'
71

Excellent idea, Neubert . This is a great approach to determine specific metrics to decide when to suspend the system.

Regarding strategy of development of the whole thing: I totally agree with you.
 
I will try this, soon.

make sure WoL functionality is enabled in a machine’s / servers BIOS so that it can be used to power on machines from a remote system without having physical access to them. The syntax is:

wake mac-address-here
wake link-layer-address-here
wake interface link-layer-address-here

To wake up server using link-layer-address 00:11:32:11:15:fc, enter:
$ sudo wake 00:11:32:11:15:fc
OR use em0 interface, enter:
$ sudo wake em0 00:11:32:11:15:fc
wake is being executed on linux ... :-/ does FreeBSD have wake?
YES, it DOES. ??
 
sorry to raise and old thread, but I've having an issue.
I keep having to force restart my system when it goes to sleep after being away from it for a while.
When I come back, my desktop's power button is flashing and I press it to wake up the system. I hear it starting up, but nothing else happens. The screen is still off and keyboard is unresponsive. The only way to get it back is to press the power button again, shut it off and restart it. This is not something I want to do all the time.
I keep my system running all the time as it acts also has a file server where others in my home can access shared folders with movies and tv shows that I've collected over the years.
I'm running 13.2-RELEASE and I'm using the KDE desktop. This is my power management setting on KDE. Is there anything else that I should be looking into?
Screenshot_20231029_194854.png
 

vgapci0@pci0:1:0:0: class=0x030000 rev=0xa1 hdr=0x00 vend
or=0x10de device=0x104a subvendor=0x19da subdevice=0x6222
vendor = 'NVIDIA Corporation'
device = 'GF119 [GeForce GT 610]'
class = display
subclass = VGA
hdac0@pci0:1:0:1: class=0x040300 rev=0xa1 hdr=0x00 vend
or=0x10de device=0x0e08 subvendor=0x19da subdevice=0x6222
 
Back
Top