Posts Tagged Script

Reverse Proxy for RaspberryPi

Edit

At the moment I am using anyway nginx as it’s kind of very easy to configure and does absolutely everything I need with almost no resource usage.
More information on the configuration can be found on its post.

I have various web services that run on my raspberry pi, probably like many other raspberry users out there.

I used Apache and lighttpd as reverse proxies to avoid opening many ports (and remembering them after) but instead just use one. But, having only 256MB of ram and seeing that usually both application consumed more quite some memory, while being anyway most of the time unused I wrote a tiny alternative in python. It works even with pypy, but that will just make you lose the memory saving advantage, so at that point you can just keep on using the reverse proxies I mentioned.

The program itself is not complete yet for my needs; I am planning to add direct SSL support and a tiny web server to serve an index of the various services I have, and IPv6 on the server side (it will try to connect to IPv6 clients if possible already)

So far I have managed to consume 1/3 less of ram of what lighttpd was using with no issues. I was even thinking about a possible xinetd version of it, but that would be probably even worse considering how many connection modern borwser create.. it will most probably just kill the machine forking too much or making the browser unable to open enough connections.. I’ll do some tests

You can find the link to the project in the code page or just here git://github.com/mellon85/proxy.git

Advertisements

,

Leave a comment

Convert Man pages to PDF

Always wanted to watch a man page in a pdf file? It is clearly needed sometimes, especially on mac, since it is the easiest way i know to print a man page or to read it not from a terminal.

The problem is solved easily for both Mac OS and linux. I had to add control for <code>pstopdf</code> too, since on mac it is called that way and has different parameters (but you may have <code>ps2pdf</code> installed with macports anyway).

#! /bin/bash

if [ $# -eq 1 ] ; then
    to_pdf=$(which ps2pdf)
    if [ -z "$to_pdf" ] ; then
        to_pdf=$(which pstopdf)
    fi

    name="$1"
    case "$to_pdf"  in
        *pstopdf) man -t "$name" | "$to_pdf" -i -o "$fname.pdf" ;;
        *ps2pdf)  man -t "$name" | "$to_pdf" - "$name.pdf" ;;
        *)        man -t "$name" > "$fname.ps"
    esac
    exit $?
fi
echo "Wrong number of parameters"
exit 1

Just call it like man2pdf gcc and you’ll get gcc.pdf

, , , , ,

1 Comment

Parallelized Make

Since the introduction of dual core machines the number of mono core machines is declined and almost no computer of that kind are sold at all. Having such a machine is clearly a big advantage, but for many things you must tell programs that you are on a multi-cpu machines to make them use all the power. So i wrote a very little and simple script to replace the default make.

Just place this script in a path before the standard make. I made a folder ~/.bin in my home directory and modified the PATH accordingly export PATH=~/.bin:$PATH


#!/bin/sh

# verbosity check
if [ "$VERBOSE" = "yes" ] ; then
	verbose=yes
fi

# Get the number of cores
if [ -z $NCPU ] ; then
    tmp=$(sysctl hw.ncpu)
    NCPU=${tmp#hw.ncpu: }
	if [ "$VERBOSE" = "yes" ] ; then
		echo "Parallelization enabled with $NCPU threads"
	fi
fi

j=$(($NCPU*5/2))
if [ ! -z $NOPMAKE ] ; then
    echo "Parallelization Disabled" >&2
    /usr/bin/make $@
    exit $?
fi

# Start the compilation in parallel
if [ ! -z "$DISTCC_HOSTS" ] ; then
    if [ -z "$HOST_COUNT" ] ; then
        export HOST_COUNT=$(echo $DISTCC_HOSTS | wc -w)
    fi
    /usr/bin/make CC='distcc /usr/bin/gcc' CXX='distcc /usr/bin/g++' -j$((j+$HOST_COUNT)) $@
else
    /usr/bin/make -j$j $@
fi

To make it work on linux the sysctl command must be replaced with a count of the lines containing “processor” in the file /proc/cpuinfo. Something like grep processor /proc/cpuinfo | wc -l

, , ,

Leave a comment