Skip to content

Commit

Permalink
actually check that pids are valid, updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Taras Glek committed Apr 21, 2013
1 parent 4715382 commit a526bf8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
27 changes: 10 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
The router steals server ip while server sleeps, then any connections to the IP are logged which triggers an awk script
# Automatically Sleeping

In the tomate firmware, copy the awk script to /jffs partion, then in the firewall script(or anywhere else in startup path) add
To put the server to sleep run `autosleep.py` as root. It will monitor auth log for ssh activity and suspend a minute after last auth log activity

```
/usr/bin/tail -f /var/log/messages |/jffs/logmon.awk &
```
# Wake up on directed TCP activity
Run `arpwake.mips br0 192.168.1.149 4C:72:B9:42:EA:97` on the router. arpwake waits for arp lookups of 192.168.1.149 and sends a WOL packet to 4C:72:B9:42:EA:97

## Future improvements
* Allow to specify a list of comma-separated IPs. This is useful for hosts with virtual machines where there may be many possible ips.
* Run a command on arp. This would be useful to start virtual machines ondemand
* Some clients(eg android) have a short ARP timeout. arpwake should spoof an arp reply to keep the client from timing out ~2-3 seconds in. Once TCP kicks in, the timeouts are huge. ATM my server takes ~7-10seconds to wake up, that's too long for android.

On the server the sleep script should execute:
```
ping -c 1 -w 1 192.168.1.254
```
to notify that the server is about to go to sleep.

Then after wake up the server should do
```
arping -U 192.168.1.149 -w 1
arping -A 192.168.1.149 -w 1
```
to flush the fake ip out of arp tables on the LAN
# Wake up via ssh for outside connections
An easier way to wake up for outside ssh connections is to use ssh ProxyCommand, where the first part of the command sends an etherwake packet. This isn't as general as above(obviously) as it's done on the clientside.
13 changes: 11 additions & 2 deletions autosleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
ls = []
while len(ls) == 0:
ls = inotifyx.get_events(ifd, 60)
# sometimes the log is missing an entry
# make sure that we only wait for live processes
for pid in list(sessions):
if not os.path.exists("/proc/%s" % pid):
print "Removing stale pid %s" % pid
sessions.remove(pid);
if len(ls) + len(sessions) == 0:
syslog.syslog("No more ssh sessions, going to sleep");
os.system("/home/taras/work/sleepyscripts/suspend.sh")
Expand All @@ -28,5 +34,8 @@
if reason == "opened":
sessions.add(pid)
else:
sessions.remove(pid)
print [sessions,line.strip()]
try:
sessions.remove(pid)
except KeyError:
print "pid %d was not available for removal"
print [sessions,line.strip()]

0 comments on commit a526bf8

Please sign in to comment.