Powered By Blogger

Freitag, 5. April 2013

Repairing dpkg after connection dropped and preventing that in the future

Recently I was logged in to my server via SSH, as suddenly the connection (UMTS network) dropped. The last command I ran was apt-get upgrade. Unfortunately, SSH does not resume a lost connection. When I issued apt-get upgrade again, I got an error that /var/cache/debconf/config.dat would be locked by another process. To solve that, it is possible to use the fsuer command:

fuser -v /var/cache/debconf/config.dat

The locking process can be killed with "kill -9 PID".

To prevent things like that happen in the future, I then installed "screen". When I log into my SSH server, I run screen and then work. If the connection drops again, I connect to my SSH server and say "screen -r" to get back to my previous session. Very useful. :-)

Montag, 4. März 2013

Read/Write data using Redis with Node JS

Today is Redis day. ;-) Now I wrote a small JavaScript app for Node JS that can query and change a key:

var http = require('http');
var redis = require('redis'),
        client = redis.createClient();
var url = require('url');

console.log('talktoredis started!');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  var testvalue = '';
  query = url.parse(req.url,true).query;
  client.get("testkey", function (err, reply) {
    testvalue = reply.toString();
    console.log('testvalue = ' + testvalue);
    res.write('Node.JS talks to Redis');
    res.write('Key "testkey" has value "' + testvalue + '".
');
    res.write('newvalue = "' + query.newvalue + '"
');
    res.write('Turn on ');
    res.write('Turn off');
    res.write('');
    res.end();
  });
  if (query.newvalue == 'on' || query.newvalue == 'off') {
    client.set("testkey", query.newvalue);
  }
}).listen(8000);


Together with my bash script written earlier this evening I can now use a web browser to change the behavior of a shell script.

A demonstration video was uploaded at YouTube.

EDIT: The source code isn't shown here correctly because it contains HTML tags. I uploaded the script here: https://www2.mkcs.at/temp/node_redis/talktoredis.js 

Get values from redis server from bash

Getting values from a redis server is also possible in (bash) shell scripts. On Github, I found a project providing two files (redis-bash-lib and redis-bash-cli) which enable such functionality. I wrote a small script that monitors a key for changes and writes a message to the screen, if the monitored key changes:

#!/bin/bash
SOMEVAR=''
OLDVAR=''
while /bin/true; do
    SOMEVAR=`redis-bash-cli -h localhost GET testkey`;
    if [ "$SOMEVAR" != "$OLDVAR" ]
    then
        echo "Value has changed from $OLDVAR to $SOMEVAR";
    fi
    OLDVAR=$SOMEVAR;
    sleep 1;
done;


Just open a terminal, start "redis-cli" und enter "set testkey perhaps", "set testkey again" or any other values and see how the script reacts to that change.

You could use redis server to exchange commands between some other software and your script. The script could evaluate the value and execute commands.

Freitag, 7. September 2012

First Look At NetBSD 6.0 RC 1

I am just fascinated! While my first look at NetBSD 6.0 Beta 2 was not so much exciting because it made me still angry that I had to use vi and edit a file in order to be able to use pkg_src (what I think almost everyone would like to do), NetBSD 6.0 RC got a real boost! In the installation process, just elect to install "pkgin" and elect to setup pkg_src. Although it was a bit frustrating that ftp.netbsd.org wasn't accessable via IPv6 and that the IPv4-server of ftp.netbsd.org always interrupts transfers (so downloading a few megabytes lasted very long), everything went smoothly. After the first boot, I commanded

pkgin install nano

and confirmed that I would like to download nano and a few seconds later, nano was installed and it worked. :-) That is how things should work! Because I don't like /bin/sh so much, I also installed bash using "pkgin". Really, I am delighted! :-) The only negative point is that "chsh" uses vi, but may be there is a way to change that. My favorite desktop XFCE is installed with the package "xfce4-desktop". Packages "xfce4-session", "xfce4-mousepad", "xfce4-settings", "xfce4-wm-themes" and "xfce4-utils" are highly recommended. After editing /etc/X11/xinit/xinitrc like describes in Chapter 9 of the NetBSD documentation it is possible to start XFCE using startx.

Donnerstag, 2. August 2012

Google Toolbar in Firefox 14.0.1

I just update Firefox from 13 to 14.0.1 and after I applied the trick described earlier this year, I was disappointed that it didn't work any more. First, I thought that Mozilla has changed its API too much so that Google Toolbar doesn't work any more. But I googled for a solution and found one in a few seconds:

http://www.philognosie.net/index.php/forum/message/2255/

And it worked! :-)

Mittwoch, 1. August 2012

Renault Fluence ZE: Ein echtes E-Auto von Renault

Nachdem es mir der Renault Twizy ja nicht gerade so angetan hatte, wagte ich für heute und morgen eine Fahrt mit dem Renault Fluence ZE. Das ZE steht dabei für Zero Emission und meint, dass das Fahrzeug während der Fahrt keine Schadstoffe in die Luft emittiert. Wird der Fluence ZE mit Strom aus regenerativen Energien wie Wasserkraft, Photovoltaik und dergleichen geladen, stimmt das ZE auch für die Energiegewinnung und man fährt tatsächlich emissionsfrei (hinsichtlich Luftschadstoffen). Wie für Elektrofahrzeuge üblich hat der Fluence ZE eine außerordentlich gute Beschleunigung schon vom Stand weg (zum Vergleich mit dem Opel Ampera zieht er ein bisschen weniger rasant weg) und ist sehr leise (daher auch sehr geringe Lärmemissionen). Etwas störend finde ich, dass die Konsole mit den Anzeigen schräg ist.

Kurzes Video: http://youtu.be/EaulA_rf82k






Etwas enttäuscht war ich vom Kofferraum, der recht klein ist. Unser Kinderwagen passt hier wahrscheinlich nicht gut rein.

Die Reichweite des Renault Fluence ZE beträgt im Winter etwa 100 km und bei normaler Temperatur, d.h. wenn man weder Klimaanlage noch Heizung benötigt, etwa 150 km. Auf 100 km kostet er also zwischen etwa € 2,90 und € 4,40 (Batterie hat 22 kWh Kapazität). Außerdem ist das Parken in Graz in der Kurzparkzone mit diesem Fahrzeug kostenlos. Mit 3 Jahren Batteriemiete kommt er bei einer Kilometerleistung von 15.000 km pro Jahr auf etwa € 32.000 (Renault Fluence ZE Preisliste). Dafür erspart man sich in diesem Zeitraum, wenn man 15.000 km pro Jahr fährt und das Fahrzeug im Mittel € 3,65 für 100 km benötigt hat, gegenüber einem Fahrzeug mit 6 l Treibstoffverbrauch bei aktuell etwa € 1,40 pro Liter Treibstoff etwa € 2.100 an Verbrauchskosten.

Montag, 2. Juli 2012

Transparent proxy: Preventing redirection for specific hosts

Recently, I used a self-written application (C#, .net Framework 2.0) that uses a web service, and suddenly it didn't work any more. The first attempt to call the service threw a network connection exception (the underlying connection was closed unexpectedly), the second one an HTTP exception (417 Expectation Failed). I first thought that something on the server would be wrong, but after some googling, I found out that it was my proxy (squid3), which runs as a transparent proxy on my home network. Consequently, it was my goal to exclude the IP address of the server that runs the web service from the iptables rule that does the redirection. I already had excluded my LAN and iptables wouldn't allow to exclude more than one IP address or subnet. So, I had to dive into "ipset". The commands are quite simple:

ipset -N noproxy iphash
ipset -A noproxy 192.168.1.0/24
ipset -A noproxy 1.2.3.4
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -m set ! --set noproxy dst -j REDIRECT --to-port 3128

"1.2.3.4" is just an example! You can replace it with any other IP address. Note that adding "192.168.1.0/24" effectively adds 256 hosts to the "noproxy" list! Unfortunately, ipset only allows to add 65.536 entries, so if you add a /16-subnet, the list is full already. Another (rather small) issue with ipset is that you cannot destroy a set while it is in use, so you always must delete the iptables rule that uses it before. But the really great advantage of ipset is that you can add and remove hosts from a set any time without touching iptables chains. For example, if I would like to allow transparent proxy for 192.168.1.6, I just do a

ipset -D noproxy 192.168.1.6

and iptables does what I want. The command means "remove 192.168.1.6" from set "noproxy".