Last active
April 11, 2024 09:57
-
-
Save realyukii/e0feea6d8fbf1b0963bab570e5828d57 to your computer and use it in GitHub Desktop.
gwrok keep-alive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('node:net'); | |
function keepAlive(ephPort, intervalId) { | |
const socket = new net.Socket(); | |
socket.setTimeout(1000); | |
socket.connect(port, process.env.GWROK_IP, () => socket.destroy()); | |
// stop the interval, indicate either the gwrok server no longer accept request | |
// or just bad internet connection and should retry if this is the case. | |
// for now we not perform retry, just stop the interval. | |
socket.on('timeout', () => { | |
clearInterval(intervalId); | |
}); | |
} | |
const intervalId = setInterval( | |
() => keepAlive(ephPort, intervalId), | |
1000 * process.env.KEEPALIVE_TIMEOUT | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# The script will prevent the gwrok client from closing the connection after 5 minutes of inactivity. | |
# usage: | |
# - start gwrok client first: | |
# setsid ./gwrok client <client parameter> &>/tmp/gwrok-http.log </dev/null | |
# - start the keep-alive: | |
# setsid ./keep-alive.sh <ip> <port> &>/tmp/gwrok-http.log </dev/null | |
while :;do printf 'GET / HTTP/1.1\r\nHost: $1\r\n\r\n' | nc $1 $2;sleep 4m;done |
for keep-alive ssh
service: while :;do nc -d -N <ip> <port>;sleep 5;done
-d
: disable stdin
-N
: immediately exit after connect
moved to another repository
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
references:
>file 2&>1
-man bash
and locate the&>
string.nohup
,setsid
,disown %
- stackoverflow, related to persisting running background program (daemon)