stop wasting cpu/mem-resources on idling services:
#!/bin/sh
while sleep 1s; do
set +e
echo wakeup
timeout -s15 3h node server.js # send SIGTERM after 3 hours
echo sleeping
echo "HTTP/1.1 302 OK\nrefresh:1;url=/\n\n" | nc -N -lp $PORT
done
make sure environment variables
PORT=9000
exist
This can also be achieved thru systemd-proxy, however with podman this runs rootless:
#!/bin/sh
export ENGINE=$(which podman || which docker)
while sleep 1s; do
set +e
echo starting
test -z $($ENGINE ps -a --filter=name=$IMAGE| head -n-1) && $ENGINE run -d --rm -p "$PORT:80" --name $IMAGE $IMAGE
$ENGINE start $IMAGE
sleep 3h; # go to sleep after 3 hours
$ENGINE stop $IMAGE
echo sleeping
echo "HTTP/1.1 302 OK\nrefresh:1;url=/\n\n" | nc -N -lp $PORT
done
make sure environment variables
PORT=9000
andCONTAINER=thttpd
exist.
export JOB="git reset --hard && git pull origin master"
export PORT=9000
socat -t2 TCP4-LISTEN:$PORT,fork,max-children=1,forever,reuseaddr SYSTEM:"$JOB",pty,echo=0;
curl http://yourserver:9000 --http0.9 # run this in your CI
now run 'curl http://yourserver:9000' from you CI/CD shellscript to trigger git pull
export JOB="ls -la"
export PORT=9000
socat -t2 TCP4-LISTEN:$PORT,fork,max-children=3,forever,reuseaddr SYSTEM:"$JOB",pty,echo=0;
curl http://localhost:9000 --http0.9 # run this in another terminal
modify max-children to configure maximum parallel jobs
export JOB="ls -la"
export PORT=9000
test -f cert.pem || { # create SSL temporary certificates
openssl req -newkey rsa:2048 -nodes -keyout private.key -x509 -days 365 -out public.crt
cat private.key public.crt > cert.pem
}
socat -t2 OPENSSL-LISTEN:$PORT,cert=cert.pem,verify=0,fork,max-children=3,forever,reuseaddr SYSTEM:"$JOB",pty,echo=0;
curl -k http://localhost:9000 # run this in another terminal
you can omit
-k
when symlinking a letsencrypt-generated certificate tocert.pem
.
you can modify max-children to configure maximum parallel jobs
cluster.sh
#!/bin/bash
mycluster="serverA serverB"
rpc(){
foo(){ echo hello from $(hostname) $*; }
"$@"
}
for server in $mycluster; do
ssh $server "$(declare -f rpc); rpc foo $*"
done
$ ./cluster.sh 123
hello from serverA 123
hello from serverB 123
$ cd myapp
$ git init
$ wget "https://raw.githubusercontent.com/coderofsalvation/podi/master/podi" && chmod +x podi
$ ./podi init git@myserver:/dir/to/deploy
$ git push git@myserver
(pipeline is triggered)
# PROFIT!
podi only requires ssh+git installed on your tiny server
redbean can serve 1 million+ gzip encoded responses per second on a cheap personal computer.
Optional: download docker-image here
$(which docker || which podman) run -it --rm -p 3000:3000 -v $(pwd):/home/static my-static-website
NOTE: for JS patterns see my JS patterns-page
NOTE: for LUA patterns see my LUA patterns-page