Git Product home page Git Product logo

sleep-on-lan's Introduction

Sleep-On-LAN (SOL)

Principle

Wake-on-LAN is a standard low-level protocol implemented in various hardware. At this time, there is not standard to make the opposite and send a computer in sleep mode.

This project allows a windows or linux box to be put into sleep from any other device.

It works with the exact same magic packet than for Wake-On-LAN, the only difference is that the MAC address has to be written in reverse order.

Technically, you have to run a little daemon (the sleep-on-lan program on your computeri, server, NAS, ... that will listen the same Wake-On-LAN port and send the computer in sleep mode when the reversed MAC address received matches a local address. Additionnaly, it can also be triggered through a REST endpoint (with something like curl). Executed commands are fully customizable.

Written in go, the code shoud run on linux and windows platforms.

Usage

Grab the latest windows + linux release or snapshot : https://github.com/SR-G/sleep-on-lan/releases/

Sleep through UDP

Just send a regular wake-on-lan command but with a reversed MAC address. Thus, the same wake-on-lan tools may be used for both wake and sleep operations (python wake-on-lan script, OpenHab WoL plugin, Android applications, and so on).

Provided you are using a wake-on-lan script like this one : wake-on-lan python script (available as a debian package for example), you may use :

wakeonlan c4:d9:87:7a:78:35 192.168.255.255 // regular mac address, will wake an asleep computer
wakeonlan 35:78:7a:87:d9:c4 192.168.255.255 // reversed mac address, will trigger the UDP listener of the sleep-on-lan process and will thus remotely sleep the computer

Sleep through REST service

If this HTTP listener is activated, the Sleep-On-Lan process then exposes a few REST services, for example :

http://127.0.0.1:8009/                               // index page, just shows local IP / mac
http://127.0.0.1:8009/sleep                          // remotely sleep this computer through this URL
http://127.0.0.1:8009/quit                           // sleep-on-lan will be exited
http://127.0.0.1:8009/wol/c4:d9:87:7a:78:35          // sends a wake-on-lan magic packet on the network to the provided mac address
http://127.0.0.1:8009/state/local                    // will output the local state of that server, in order to remotely knows if the server is alive or not
http://127.0.0.1:8009/state/ip/:ip                   // will output the local state of a remoter server for which IP is provided

(all available endpoints are displayed in the logs of the process when it starts)

Example of HTTP endpoint

You can then easily send any computer running Sleep-On-LAN with an HTTP request, with CURL or anything else : curl http://192.168.8.4:8009/sleep/, for example.

All other registered custom commands (per configuration) can be triggered in the same way.

Configuration

An optional configuration file may be used. See configuration examples. Order of priority for configuration filenames are :

  1. The filename manually configured inside the command line with the --config parameter (if available on disk)
  2. (linux only) A filename under /etc/sol.json (if available on disk)
  3. (linux only) A filename under /etc/sleep-on-lan.json (if available on disk)
  4. A filename alongside the sol binary (i.e., in the same folder) and named sol.json (if available on disk)
  5. Otherwise, default values will be taken in account

Content of configuration is as follow (everything is optional / below is the whole structure) :

{
  "Listeners" : ["UDP:9", "HTTP:8009" ],
  "Auth" : {
      "Login" : "myusername",
      "Password" : "mypassword"
  },
  "ExitIfAnyPortIsAlreadyUsed" : false,
  "AvoidDualUDPSending" : {
          "Active": true,
          "Delay": "100ms"
  },
  "LogLevel" : "INFO",
  "BroadcastIP" : "255.255.255.255",
  "Commands" : []
}

Listeners defines which mechanism will be activated

  • UDP : will listen on the default port (= 9)
  • UDP:<port> : will listen on the provided port
  • HTTP : will listen on the default port (= 8009)
  • HTTP:<port> : will listen on the provided port

Several listeners may be defined (e.g., "UDP:7", "UDP:9", "HTTP:8009")

If no configuration file is provided, UDP:9 and HTTP:8009 are assumed by default.

The REST services are exposed on 0.0.0.0 and are thus accessibles from http://localhost/, http://127.0.0.1/, http://192.168.1.x/ and so on.

Rest service may be secured if needed through an optional Auth configuration (a Basic Auth is triggered on all REST services as soon as this Auth section is defined) :

{
  "Listeners" : ["UDP:9", "HTTP:8009" ],
  "Auth" : {
      "Login" : "myusername",
      "Password" : "mypassword"
  }
}

Authed REST may still be triggered from a remote host, if needed, through :

curl http://myusername:mypassword@<IP>/sleep/

Default output from REST command is XML but may be switched from a configuration point of view (by adding a HTTPOutput : 'JSON') or on a per-request basis (by adding a ?format=JSON to the request, one would retrieve a JSON result).

LogLevel defines the log level to use. Available values are NONE|OFF, DEBUG, INFO, WARN|WARNING, ERROR. Logs are just written to the stderr/stdout outputs.

BroadcastIP defines the broadcast IP used by the /wol service. By default the IP used is 192.168.255.255 (local network range).

ExitIfAnyPortIsAlreadyUsed if true, the daemon will stop if any port can't be started, whereas if false (which is the default), it will continue to start (you may be willing the daemon to be running even if one listener is not startable).

AvoidDualUDPSending to activate one internal mechanizm allowing a small delay before executing commands. This may allow dual UDP sent by some clients to be discarded, instead of being executed twice. False by default. Delay (if feature is enabled) is 100ms by default (can be overriden to something like "1s", ...)

{
  "LogLevel" : "INFO",
  "AvoidDualUDPSending" : {
          "Active": true,
          "Delay": "100ms"
  }
}

Commands defines the available commands.

By default, on both windows and linux, only one command is defined : sleep command (through systemctl suspend on (recent) systemd linux, pm-suspend on (old) linux and a DLL API call on windows).

You may customize / override this behavior, or add new commands (that will then be available under http://<IP>:<HTTP PORT>/<operation> if a HTTP listener is defined), if needed.

Each command has 4 attributes :

  • "Operation" : the name of the operation (for the HTTP url)
  • "Type" : the type of the operation, either "external" (by default, for remote execution) or "internal-dll" (on windows, to trigger a sleep through a DLL API call)
  • "Default" : true or false. Default command will be executed when UDP magic packets are received. If only one command is defined, it will automatically be the default one
  • "Command" : for external commands, the exact command that has to be executed (see examples below). May have to contain full path on windows.

Example 1 : only one (default) operation that will shutdown the system on windows. Through HTTP, the operation will be triggerable with http://<IP>:<PORT_HTTP>/halt/.

  "Commands" : [ 
    {
        "Operation" : "halt",
        "Command" : "C:\\Windows\\System32\\Shutdown.exe -s -t 0"
    }]

Example 2 : force sleep on windows through the rundll32.exe trick (and not through the default API call)

  "Commands" : [ 
    {
        "Operation" : "sleep",
        "Command" : "C:\\Windows\\System32\\rundll32.exe powrprof.dll,SetSuspendState 0,1,1"
    }]

Example 3 : default operation will put the computer to sleep on linux and a second operation will be published to shutdown the computer through HTTP.

  "Commands" : [ 
    {
        "Operation" : "halt",
        "Command" : "pm-halt",
        "Default" : false
    },
    {
        "Operation" : "sleep",
        "Command" : "pm-sleep",
        "Default" : true
    }]

Installation

Under windows

The Sleep-On-Lan process may be run manually or, for convenience, installed as a service. The easiest way to install the Sleep-On-Lan service is probably to use NSSM (the Non-Sucking Service Manager). To be executed as admin (Right click on the .cmd file that you created > Execute as administrator).

Usage :

nssm install <service name> <full path to binary>

Installation example :

c:\Tools\nssm\2.24\win64\nssm.exe install SleepOnLan c:\Tools\Sleep-On-Lan\sol.exe

Removal example :

c:\Tools\nssm\2.24\win64\nssm.exe remove SleepOnLan confirm

Configure logs of the service in an external file (adjust the paths as needed) :

C:\Tools\nssm\2.24\win64\nssm.exe set SleepOnLan AppStdout "C:\Tools\SleepOnLan\sleeponlan-windows.log"
C:\Tools\nssm\2.24\win64\nssm.exe set SleepOnLan AppStderr "C:\Tools\SleepOnLan\sleeponlan-windows.log"

Reference : nssm

Under Linux

Port & rights on processes

The Sleep-On-Lan process must use (usually) port 9 (see configuration section if you need another port or if you need to listen to several UDP ports).

Thus the process has either to be ran as root, either has to have the authorization to start on ports < 1024.

The following example allows the process to run on ports < 1024 on recent Linux kernels (for example on ubuntu) :

sudo setcap 'cap_net_bind_service=+ep' /path/to/sol_binary
nohup /path/to/sol_binary > /var/log/sleep-on-lan.log 2>&1 &

So to summarize : if you are facing the error inside logs listen udp :9: bind: permission denied, you either need to run the program as root, either to apply the proper setcap permission.

Daemonization

You may of course daemonize the process or launch it through an external monitor :

  • monit
  • supervisor
  • systemctl
    1. Create the file /etc/systemd/system/sleep-on-lan.service with the following content (adjust the path accordingly to your installation)
      [Unit]
      Description=Sleep-On-LAN daemon
      
      [Service]
      User=root
      WorkingDirectory=/home/applications/sleep-on-lan
      ExecStart=/home/applications/sleep-on-lan/sol
      Restart=always
      
      [Install]
      WantedBy=multi-user.target
      
    2. Refresh configuration, activate service at runtime and start it :
      systemctl daemon-reload
      systemctl enable sleep-on-lan.service
      systemctl start sleep-on-lan.service
    3. Logs are then found in a regular way inside journalctl (journalctl -xe, ...)

Miscellaneous

Available commands

Just launch sol help :

Sleep-On-LAN - Daemon allowing to send a linux or windows computer to sleep

  Usage:
    Sleep-On-LAN [generate-configuration]

  Subcommands: 
    generate-configuration   Generate a default configuration JSON file

  Flags: 
       --version   Displays the program version string.
    -h --help      Displays help with available flag, subcommand, and positional value parameters.
    -c --config    Configuration file to use (optional, default is 'sol.json' next to the binary)
    -v --verbose   Force DEBUG log level (will override what may be defined in JSON configuration)

Generate a default configuration

Just launch either sol generate-configuration (console output) or sol --config sol-default.json generate-configuration to generate a valid default configuration (the same ones than what is applied if no external configuration is applied). Remember that to use that file (once generated and updated), you have either to name it exactly like the binary name + JSON extension (probably sol.json), or to specify a specific path with the --config command line configuration parameter.

{
    "Listeners": [
        "UDP:9",
        "HTTP:8009"
    ],
    "LogLevel": "INFO",
    "BroadcastIP": "192.168.255.255",
    "ExitIfAnyPortIsAlreadyUsed": false,
    "Commands": [
        {
            "Operation": "sleep",
            "Command": "systemctl suspend",
            "Default": true,
            "Type": "external"
        }
    ],
    "Auth": {
        "Login": "",
        "Password": ""
    },
    "HTTPOutput": "XML",
    "AvoidDualUDPSending": {
        "Active": false,
        "Delay": "100ms"
    },
    "DelayBeforeCommands": {
        "Active": true,
        "Delay": "500ms"
    }
}

Troubleshooting

If Sleep-on-LAN cannot be triggered remotely, but the service is running and the ports are open, a firewall may be in the way. For example on Windows 10, add a rule to Windows Defender to allow incoming TCP traffic on port 8009 for the REST example above.

Logs

Expected logs when starting the process should be :

Example of start logs

Standalone sleep on lan under windows

Another way to sleep a windows computer remotely :

net rpc SHUTDOWN -f -I xxx.xxx.xxx.xxx -U uname%psswd

Other similar projects

  • Sleep On Lan (pure java implementation, magic anti-packet starts with 6 * 0x00 instead of 6 * 0xFF)

OpenHab v2 configuration

Example of configuration under OpenHab (2.x).

OpenHab

This is a very standard configuration : MAC addresses have just to be reversed.

Switch  Network_WoL_Solaris   	"Wake PC (solaris)"   		(WoL, Status, Network)   { wol="192.168.8.255#14:da:e9:01:98:19" }
Switch  Network_WoL_Jupiter   	"Wake PC (jupiter)"   		(WoL, Status, Network)   { wol="192.168.8.255#bc:5f:f4:2b:df:26" }
Switch  Network_WoL_Laptop   	"Wake PC (laptop)"    		(WoL, Status, Network)   { wol="192.168.8.255#C4:D9:87:7A:78:35" }

Switch  Network_SoL_Solaris   	"Sleep PC (solaris)"  		(WoL, Status, Network)   { wol="192.168.8.255#19:98:01:e9:da:14" }
Switch  Network_SoL_Laptop   	"Sleep PC (laptop)"   		(WoL, Status, Network)   { wol="192.168.8.255#35:78:7A:87:D9:C4" }

Developement

Regular operations

A few commands are available through the provided Makefile :

  • Launch a golang docker container (to be executed from host) :
make docker
  • Create binaries (from the inside of the container) :
make install
  • Create distribution (from the inside of the container - note, zip package is required) :
make distribution
  • Clean everything :
make clean
  • Launch the generated binary (from the inside of the container) :
make run

Release procedure

  • Update release version in makefile
  • Commit everything & create new tag
git add .
git commit -m"Prepare 1.1.0 RELEASE"
git push origin master
git tag 1.1.0-RELEASE 
git push origin 1.1.0-RELEASE 
  • Create distribution export GOPATH=~/go/ ; make distribution and upload the ZIP generated under bin/*.zip on GitHub
  • Change Makefile (increase number, switch back to SNAPSHOT)

sleep-on-lan's People

Contributors

majorpeter avatar skrimix avatar sr-g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sleep-on-lan's Issues

Sending PC into sleep randomly

I am not 100% sure its the sleep-on-lan script but just curious if anyone has experienced this issue. It could be home-assistant which I am using to control and automate smart devices in my home. When sleep on lan service is (most recently while playing a game) the PC is sent into sleep mode. When I disable it the PC no longer is sent into sleep. I will check my home-assistant logs to see if its sending out a command occasionally. Any idea or ever heard of this happening?

New --verbose parameter

Just about easing debug.
By default log level is INFO.
Log level may be overriden :

  • through JSON configuration (see configuration examples or configuration documentation)
  • through that new --verbose parameter
    The --verbose parameter has a higher priority than what may be configured in JSON file.

Add internal shutdown command

Per idea by @AtmanActive in fork.

Automatically declared if no configuration file is provided.
Can be re-declared if needed as a command named "shutdown" and type "internal-dll".

Have extra delay before executing command

A GOLANG "defer" was already in place, but due to the internal GOLANG framework used here for HTTP handlers and depending on the computer being used, HTTP answers could be skipped before sleep being executed.

Hence a new possible configuration :

This is now activated by default with a 500ms value

@reb

Works well when run at command line but when trying to use supervisor the server clearly starts as I'm getting a response:
<result> <application>sleep-on-lan</application> <hosts> <host ip="fe80::c23f:d5ff:fea0:94f0/64" mac="c0:3f:d5:a0:94:f0"/> <host ip="10.71.10.6/32" mac=""/> <host ip="127.0.0.1/8" mac=""/> <host ip="::1/128" mac=""/> <host ip="192.168.0.128/24" mac="c0:3f:d5:a0:94:f0"/> <host ip="192.168.11.5/24" mac="c0:3f:d5:a0:94:f0"/> </hosts> <listeners> <listener type="UDP" port="9" active="true"/> <listener type="UDP" port="7" active="true"/> <listener type="HTTP" port="8009" active="true"/> </listeners> </result>

But when calling /sleep/ nothing happens, I just get the same response above. Unlike when I start from the command line, so I'm quite confused. Supervisor conf is as simple as they come:
[program:cat] command=/home/main/SleepOnLAN-1.0.0-SNAPSHOT/linux/sol

PS I'm running debian.

Any Ideas?

Custom commands don't work in linux

Hi, I'm configuring sleep-on-lan for halt the system and I write this in the sol.json:

{
"Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
"LogLevel" : "INFO",
"Commands" : [
{
"Operation" : "poweroff",
"Command" : "poweroff"
}]
}

I try this configuration and don't work too:
{
"Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
"LogLevel" : "INFO",
"Commands" : [
{
"Operation" : "halt",
"Command" : "pm-halt"
}]
}

The log:
INFO: 2016/12/10 12:18:07 sol.go:19: Now starting sleep-on-lan, hardware IP/mac addresses are :
INFO: 2016/12/10 12:18:07 sol.go:21: - local IP adress [127.0.0.1/8], mac []
INFO: 2016/12/10 12:18:07 sol.go:21: - local IP adress [::1/128], mac []
INFO: 2016/12/10 12:18:07 sol.go:21: - local IP adress [192.168.1.XXX/24], mac [aa:aa:aa:aa:aa:aa]
INFO: 2016/12/10 12:18:07 sol.go:21: - local IP adress [172.17.0.1/16], mac [aa:aa:aa:aa:aa:aa]
INFO: 2016/12/10 12:18:07 listener_udp.go:13: Now listening UDP packets on port [9]
INFO: 2016/12/10 12:18:07 listener_udp.go:13: Now listening UDP packets on port [7]
INFO: 2016/12/10 12:18:07 listener_http.go:126: Now listening HTTP on port [8009], urls will be :
INFO: 2016/12/10 12:18:07 listener_http.go:129: - http://192.168.1.XXX:8009/sleep
INFO: 2016/12/10 12:18:07 listener_http.go:129: - http://192.168.1.XXX:8009/wol/[A-z]+
INFO: 2016/12/10 12:18:07 listener_http.go:129: - http://192.168.1.XXX:8009/

Ther are any problem with json configuration?

Many Thanks

add commands doesn't work

Hi Serge, Thanks for this usefull application , it works verry good.
but . . . I'll tried to add somme commands, like restart, and it doesn' permite..
config sol.json working good is :
{
"Listeners" : ["UDP:9", "UDP:7", "HTTP:57072" ],
"LogLevel" : "INFO",
"BroadcastIP" : "192.168.1.255",
"ExitIfAnyPortIsAlreadyUsed" : false,
"AvoidDualUDPSending" : {
"Active": true,
"Delay": "100ms"
}
}

I try to add with this but it refuse to start the app, or the service:
{
"Listeners" : ["UDP:9", "UDP:7", "HTTP:57072" ],
"LogLevel" : "INFO",
"BroadcastIP" : "192.168.1.255",
"ExitIfAnyPortIsAlreadyUsed" : false,
"AvoidDualUDPSending" : {
"Active": true,
"Delay": "100ms"
},
"Commands" : [
{
"Operation" : "restart",
"Type" : "external",
"Command" : "C:\Windows\System32\Shutdown.exe /r /f /t 0",
"Default" : "false"
}]
}

can you help me please ?

Thanks a lot , have a nice day

A wake up equal a sleep

Hello,

Good work !
A little problem : Each time I wake up the computer (with the mouse or with a WOL packet) it'es interpretated like a sleep request.
How ??? :(
So I can't let your soft running

Allow HTTP Basic Auth authentification

Optional Basic Auth

{
  "Listeners" : ["UDP:9", "HTTP:8009" ],
  "Auth" : {
      "Login" : "myusername",
      "Password" : "mypassword"
  }
}

New log are :

INFO: 2017/12/20 13:10:27 listener_http.go:92: HTTP starting on port [8009], without auth
... or
INFO: 2017/12/20 13:10:55 listener_http.go:94: HTTP starting on port [8009], with auth activated : login [myusername], password [**********]

Extra default filenames

@see documentation in README.md, now configuration may be :

  1. From --config
  2. (linux only) from /etc/sol.json
  3. (linux only) from /etc/sleep-on-lan.json
  4. In a sol.json file located in the same directory than the binary
  5. If no configuration files are found (not configured, not available, ...) then default values are applied

Incorrect example for Commands?

Hi - I was struggling quite a while to get systemctl suspend to work instead of relying on pm-utils, which is no longer supported on Debian 11.

Then I finally realized I was basing my work on an incorrect example in the docs:

  "Commands" : [ 
    {
        "Operation" : "halt",
        "Command" : "pm-halt",
        "Default" : "false"
    },
    {
        "Operation" : "sleep",
        "Command" : "pm-sleep",
        "Default" : "true"
    }]

Quotes around the value for the attribute Default are incorrect, right?

Here's what failed for me:

{
  "Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
  "LogLevel" : "INFO",
  "ExitIfAnyPortIsAlreadyUsed" : true,
  "AvoidDualUDPSending" : {
          "Active": false,
          "Delay": "100ms"
  },
  "Commands" : [
    {
        "Operation" : "sleep",
        "Command" : "/usr/bin/systemctl suspend",
        "Default" : "false" <<<<======
    }]
}

And here's what worked:

{
  "Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
  "LogLevel" : "INFO",
  "ExitIfAnyPortIsAlreadyUsed" : true,
  "AvoidDualUDPSending" : {
          "Active": false,
          "Delay": "100ms"
  },
  "Commands" : [
    {
        "Operation" : "sleep",
        "Command" : "/usr/bin/systemctl suspend",
        "Default" : false <<<<======
    }]
}

Excellent utility by the way, thanks for putting it out there!

Add a "state" internal command on HTTP connector

If HTTP connector is activated, new routes are published :

INFO: 2017/12/20 18:01:14 listener_http.go:87: Registering route [/state/local]
INFO: 2017/12/20 18:01:14 listener_http.go:87: Registering route [/state/ip/:ip]

Then triggering curl http://localhost:8009/state/ip/192.168.8.222 gives :

INFO: 2017/12/20 18:01:33 listener_http.go:95: Checking state of remote host with IP [192.168.8.222]
INFO: 2017/12/20 18:08:27 listener_http.go:111: Ping results for [192.168.8.222], [5] packets transmitted, [0] packets received, [100.00] packet loss

With the corresponding XML result :

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <state>offline</state>
  <host>192.168.8.222</host>
</result>

And curl http://localhost:8009/state/ip/192.168.8.1 (working IP) or curl http://localhost:8009/state/local gives :

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <state>online</state>
  <host>localhost</host>
</result>

In addition, a "/state/local/online" special HTTP route is available and is just generating a "true|false" result to allow easy parsing.

Moreover, other requests can now be outputed as XML (default, as it was until now) or JSON (through configuration or on a per-request basis, @see README.md)

Log file or event log on Windows?

Hi! I'm trying to use this very interesting tool and got it working flawlessly on Linux, but have some issues on Windows 10.
I have a config like this:

{
  "Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
  "LogLevel" : "INFO",
  "ExitIfAnyPortIsAlreadyUsed" : true,
  "AvoidDualUDPSending" : {
    "Active": false,
    "Delay": "100ms"
  },
  "Commands" : [{
     "Operation" : "sleep",
     "Command" : "c:\\bin\\psshutdown.exe -d -t 0 -v 0",
     "Default" : true
   }, {
     "Operation" : "reboot",
     "Command" : "c:\\windows\\system32\\shutdown.exe /r /f /t 0 /d u:0:0",
     "Default" : false
   }, {
     "Operation" : "killgames",
     "Command" : "C:\\Windows\\System32\\cmd.exe /c d:\\home\\Serge\\bin\\vanya-killgames.cmd",
     "Default" : false
   }]
}

And I found that from time to time it stops working at all when runnign as a service (installed via NSSM):

~ » curl -v http://dzeta.home:8009/sleep
*   Trying 192.168.113.7:8009...
* Connected to dzeta.home (192.168.113.7) port 8009 (#0)
> GET /sleep HTTP/1.1
> Host: dzeta.home:8009
> User-Agent: curl/7.81.0
> Accept: */*
> 
^C
~ » curl -v http://dzeta.home:8009/sleep
*   Trying 192.168.113.7:8009...
* Connected to dzeta.home (192.168.113.7) port 8009 (#0)
> GET /sleep HTTP/1.1
> Host: dzeta.home:8009
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Sun, 03 Jul 2022 17:40:55 GMT
< Content-Length: 120
< Content-Type: text/xml; charset=utf-8
< 
<?xml version="1.0" encoding="UTF-8"?>
<result>
  <operation>sleep</operation>
  <successful>true</successful>
* Connection #0 to host dzeta.home left intact
</result>%                   

The first case is it's running as a service, the second - running manully in admin-level cmd.
Also wakeonline command with reversed MAC doesn't work in first case as well.

Is there any way to see activity as log (file or windows events) when running as a service?

No response for HTTP sleep

Hey,

When I call the sleep URL with curl, the curl don't get any response and just hanging. The computer immediately goes into sleep however.

This is causing HomeBridge thinks the command failed.

Could this URL give back a 200 OK blank page or something? This should solve this.

Thanks,
Mark

Windows 10 Run as administrator

Hi

Was testing by just running sol.exe
I thought this application wasn't working.
Tried opening the 8009 port in firewall
Still not working

Then I right clicked, run as adminstrator and it started working.
Maybe should mention this in the documentation?

Thanks for the application, will try it as a service now that I know it is working.

Response not returned before command executed

I am using sol.exe with the Windows sleep command in Example 2.

"Commands" : [ { "Operation" : "sleep", "Command" : "C:\\Windows\\System32\\rundll32.exe powrprof.dll,SetSuspendState 0,1,1" }]

I use a PHP WakeOnLan/SleepOnLan web app on a Raspberry Pi which expects a HTTP response to know if the sleep request was successful or not. The problem I'm seeing is that my computer is going to sleep before the RaspberryPi receives the HTTP response back so the request times out even though sol.exe successfully puts the computer to sleep. Is there any way for the HTTP response to be sent before the sleep command is executed? Thank you.

Custom commands don't work

sol.exe 1.0.1 on windows 7 x64 SP1

I have tried everything, but I simply can't make custom commands work.

If I remove the section '"Commands" : [ { "Operation" : "halt", "Command" :"..." } ]', then going through the REST interface I can issue the 'sleep' command and sol.exe will execute it.

If I add that section, sol.exe does recognize that command by showing information about it in the REST XML output. I also can issue that URL, and sol.exe responds with 'Executing operation [halt]', but nothing happens. Nothing is executed whatsoever.

I have tried with simple notepad.exe, copying it to sol.exe's folder and with relative paths, also with slashes instead of backslashes - nothing.

No go.

4 command executions for 1 sent UDP packet ?

Hi,
First of all thank you for this projet, it's very useful.

When I send 1 "UDP SoL packet" (with Mocha VNC Lite on iPhone), it results (after the log info) with 4 executions of the shutdown command in my case. The server shutdowns correctly but there is a quite annoying issue. If I try to restart the computer immediately (WoL packet), it's shut down again after several seconds.
My guess is the others UDP SoL packets were stuck in some buffer and once the network card is up it is turned off again. Is that possible?
Could it be that I ran the service 4 times and badly killed it? (even after rebooting.. I don't think so)

Log errors are just a user permission issue. This log is the result of 1 UDP SoL packet, is it normal it executes 4 times ?

capture d ecran 2017-12-20 a 11 27 40

Some features you could add:
-A REST "login page" to secure the Sleep on Wan
-A REST page to know the machine state (on/off)

Service fails to start on Windows 10 version 1703

These are the logs from Event Viewer:

Service SleepOnLan received START control, which will be handled.
Started C:\Program Files\SleepOnLAN-1.0.0\windows\sol.exe for service SleepOnLan in C:\Program Files\SleepOnLAN-1.0.0\windows.
Program C:\Program Files\SleepOnLAN-1.0.0\windows\sol.exe for service SleepOnLan exited with return code 3221225794.
Killing process tree of process 8252 for service SleepOnLan with exit code 3221225794
Killing PID 8252 in process tree of PID 8252 because service SleepOnLan is stopping.
Service SleepOnLan action for exit code 3221225794 is Restart. Attempting to restart C:\Program Files\SleepOnLAN-1.0.0\windows\sol.exe.
Service SleepOnLan ran for less than 1500 milliseconds. Restart will be delayed by 2000 milliseconds.

When running from PowerShell it starts normally and functions correctly.

Win 32bit ver?

Any chance for 32bit Win version binaries?

I guess i can compile it myself :) but still would be nice to have em here

Confirmation Dialog

Awesome program. A really useful feature would be to display a confirmation dialog on the computer that was being put to sleep so that a user wouldn't be unexpectedly get locked out. I could imagine opening a dialog window on computer that timed out after 30 seconds allowing the user to cancel the sleep request. Thanks!

Getting confused with syntax and versions

I have downloaded the 1.0.6 snapshot version here a couple of weeks ago.
But now I don't understand this:
sol.json:

{
  "Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
  "LogLevel" : "INFO",
  "AvoidDualUDPSending" : {
	  "Active": false,
	  "Delay": "100ms"
  }
  "Commands" : [ 
    {
        "Operation" : "hibernate",
        "Command" : "nircmd hibernate",
        "Default" : "true"
    },
    {
        "Operation" : "sleep",
        "Command" : "nircmd sleep",
        "Default" : "false"
    },
    {
        "Operation" : "reboot",
        "Command" : "nircmd exitwin reboot",
        "Default" : "false"
    }]
}

works fine with what presumably is the 1.0.6 Version (11MB filesize, date Oct 17)
If I use it on 1.0.5 only the sleep command would be functional. For the rest I get "not found" errors.

Any explanation for that?
I can't find any syntax issues.

I have to add: If I leave

"AvoidDualUDPSending" : {
	  "Active": false,
	  "Delay": "100ms"
  }

out, it works with 1.0.5
But this section is part of the 1.0.5 sol.json

Shutdown-on-LAN

Hello Serge,

Thank you very much for this great software.

Would it be too much to ask to also add shutdown functionality?
Preferably via config option.

Here is my usage scenario:
I have built a Steam machine based on windows for my kids to play Lego games.
It is connected to Samsung Smart TV which is also connected with ethernet to my home network.
In my home network I use MikroTik as my home router and this router is pretty advanced, it can even do scripting, so with two lines of code I have instructed it to ping my TV's IP and when it detects that it is down (TV off) to send magic packet to MAC address A, and when it detects that the state changed from down to up (TV on) to send magic packet to MAC address B.
Now, this motherboard (Gigabyte GA-Z97N-WIFI) and Intel ethernet chip support wake-on-lan even from shutdown state, which is awesome.
And I would always prefer for the machine to go to shutdown and boot back on when needed, then to go sleep-wake-sleep-wake. Still to this day, for millions of unknown reasons, windows machine runs smoothly only after a fresh boot, while after a week of running dozens of steam games (without any sleep or shutdown) something always goes wrong and the machine runs jerky and slowed down.
So, the only piece I am missing right now is Shutdown-on-LAN.
Using windows' built-in idle timers is impossible as kids will always leave a full screen game on pause and that will prevent any idle detection.

Let me know what do you think about this.

Thanks.

Cheers!

Split README.md into separated pages

README.md starts to be a bit long : split it into dedicated pages ("How to install SOL as a service", "Developer tasks", "Troublehsooting", ...)

Fedora 30 not receiving magic packets on UDP

The binary runs fine and it's being run with sudo, I get no errors but doesn't seems to be seeing the mp I'm sending it from my linux laptop. I double checked to see if it wasn't a typo in the reversed mac, but no. Here's the output:

https://pastebin.com/CjCPLa6B

Could it be firewalld blocking the script? I have no knowledge on how to whitelist a binary in it tho. WOL works fine btw.

Make error

It'd seem tensin-app-golang isn't available, do we need your stack, too?

Unable to find image 'tensin-app-golang:latest' locally

image

Create non-console version, so conhost.exe doesn't also need to run

Thank you for sol, it's working well for my needs. However, being a console app it also spawns a conhost on Windows, even when console output is directed to a file. An additional conhost consumes more memory than both sol and nssm combined, which is rather a shame as in a service configuration we don't need a console anyway.

Would it be possible to compile this as a non-console app as well, so it doesn't generate a conhost?

Many thanks for your work!

Can't make UDP WOL packet work on windows

sol.exe 1.0.1 on windows 7 x64 SP1

So, my Mikrotik is sending these:

ON:  tool wol interface=LAN mac=FC:AA:14:2B:58:EA
OFF: tool wol interface=LAN mac=EA:58:2B:14:AA:FC

sol.json: default as stated here: https://github.com/SR-G/sleep-on-lan

My machine wakes up alright, but sol.exe won't put it to sleep.
If I try the same thing via REST interface, then, yes it does work.

For now, I am using the workaround where my MikroTik can send REST commands as well, so I just added:
OFF: tool fetch url="http://192.168.173.18:8009/sleep" mode=http

and now it does sleep as intended.
But this is a workaround, not an intended behavior.

Thanks.

Have better "default configuration" generated

"generate-configuration" options is now a bit more standard.

sol generate-configuration will dump a default configuration on the console
sol --config sol-default.json generate-configuration will dump a default configuration inside the provided configuration filename. Will fail if that filename already exists.

Example :

Example of possible default configuration (to be stored alongside sol binary in a filename like [sol.json])
{
    "Listeners": [
        "UDP:9",
        "HTTP:8009"
    ],
    "LogLevel": "INFO",
    "BroadcastIP": "192.168.255.255",
    "ExitIfAnyPortIsAlreadyUsed": false,
    "Commands": [
        {
            "Operation": "sleep",
            "Command": "systemctl suspend",
            "Default": true,
            "Type": "external"
        }
    ],
    "Auth": {
        "Login": "",
        "Password": ""
    },
    "HTTPOutput": "XML",
    "AvoidDualUDPSending": {
        "Active": false,
        "Delay": "100ms"
    }
}

Also default command is now attached (and updated to "systemctl")

Can't run powershell script.

Hi,

I am trying to run powershell script:

	{
		"Operation" : "playvideo",
		"Command" : "powershell.exe -file D:\\hassio\\firefoxOnDesktop.ps1",
		"Default" : false
	}

It works when opening from usual cmd, but not via sleep on lan tool.

Not Found Message for new Commands

I have added a new command to sol.json
The one from the examples: "halt" and "Command" : "C:\Windows\System32\Shutdown.exe -s -t 0"
But I always get a Not found message, doesn't matter which command I try.
Guess is a syntax problem:
ERROR: configuration.go:64: error while loading configuration : invalid character '"' after object key:value pair
What am I doing wrong?

Does it still work on Linux?

Hello! Thank you for your work on this project!

I have tried to run it on Ubuntu Server 18.04, but it does not seem to work. Even logs are empty.
I tries to run it by command from example

sudo setcap 'cap_net_bind_service=+ep' /path/to/sol_binary
nohup /path/to/sol_binary > /var/log/sleep-on-lan.log 2>&1 &

Through ps aux I see that this sol process is running and by tcpdump I see that packets are captured by NIC. But no logs from sol binary are presend and pc is not put into sleep.

Possibly I did something wrong or should I recompile this first if it could help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.