Skip to content

Instantly share code, notes, and snippets.

View pnbv's full-sized avatar

pedro vasconcelos pnbv

View GitHub Profile
#! /bin/sh
if test "$2" = ""; then
echo "usage: $0 basedir depth"
exit 1
fi
if test "$2" = "0"; then
exit 0
fi
@suda
suda / nginx_memcache_set_simplehttpserver.py
Created November 16, 2010 15:08
[Python] Simple backend for nginx memcached module
"""
Simple backend for nginx memcached module
Written by Wojtek 'suda' Siudzinski <admin@suda.pl>
Gist: https://gist.github.com/701904
Nginx config:
location /static {
add_header X-Origin Memcached;
expires modified +48h;
@jdmaturen
jdmaturen / worker3.py
Created January 25, 2011 03:42
Redis stats aggregator w/ Gevent
import gevent
from gevent import monkey
monkey.patch_socket()
import hashlib
import os
import redis
@jed
jed / LICENSE.txt
Created May 10, 2011 23:27 — forked from 140bytes/LICENSE.txt
calculate # of ms/seconds/minutes/hours/days in the past
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@haochi
haochi / LICENSE.txt
Created July 10, 2011 23:23 — forked from 140bytes/LICENSE.txt
tofu: tiny templating engine
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Haochi Chen <http://ihaochi.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@drmalex07
drmalex07 / README-setup-tunnel-as-systemd-service.md
Last active May 29, 2024 09:32
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/secure-tunnel@.service. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
@drmalex07
drmalex07 / README-python-service-on-systemd-activated-socket.md
Last active January 13, 2024 12:53
An example network service with systemd-activated socket in Python. #systemd #python #socket #socket-activation

README

The example below creates a TCP server listening on a stream (i.e. SOCK_STREAM) socket. A similar approach can be followed to create a UDP server on a datagram (i.e. SOCK_DGRAM) socket. See man systemd.socket for details.

An example server

Create an simple echo server at /opt/foo/serve.py.

@drmalex07
drmalex07 / README-oneshot-systemd-service.md
Last active May 15, 2024 10:52
An example with an oneshot service on systemd. #systemd #systemd.service #oneshot

README

Services declared as oneshot are expected to take some action and exit immediatelly (thus, they are not really services, no running processes remain). A common pattern for these type of service is to be defined by a setup and a teardown action.

Let's create a example foo service that when started creates a file, and when stopped it deletes it.

Define setup/teardown actions

Create executable file /opt/foo/setup-foo.sh:

@drmalex07
drmalex07 / README-setup-socket-activated-systemd-service.md
Last active December 26, 2023 05:13
An example inetd-like socket-activated service. #systemd #inetd #systemd.socket

README

This is an example of a socket-activated per-connection service (which is usually referred to as inetd-like service). A thorough explanation can be found at http://0pointer.de/blog/projects/inetd.html.

Define a socket unit

The key point here is to specify Accept=yes, which will make the socket accept connections (behaving like inetd) and pass only the resulting connection socket to the service handler.

@drmalex07
drmalex07 / README-setup-systemd-timer.md
Last active May 11, 2023 19:17
An example systemd timer. #systemd #timer #systemd.timer #cron #cronjob

README

Timers provided by systemd can be used as cronjob replacements. More at man systemd.timer.

Suppose we want to periodically trigger cleanup tasks for a baz utility. We 'll create a baz-cleanup.service which will be triggered by a baz-cleanup.timer.

Define the target service unit

Create a minimal service at /etc/systemd/system/baz-cleanup.service: