Postfix fix wrong sender address

So, I, ahem, ”forgot” to change sender address on one of our servers the other day which resulted in a bunch of undeliverable mails on the mailserver which got rejected because the sender domain didn’t exist anymore. This is how I fixed it.

First, I created a map file in which you map out the old wrong address and the new shiny working one as such:

vim /etc/postfix/sender_canonical
sender@oldomain.nx  sender@newexistingdomain.com

run

postmap /etc/postfix/sender_canonical

then add following line to /etc/postfix/main.cf

sender_canonical_maps = hash:/etc/postfix/sender_canonical

after that reload postfix config

service postfix reload

requeue all deferred mails (or use -i to requeue specific id)

postqueue -f

then you can flush the queue if you don’t want to wait

postfix flush

and voila! Now all old mails that were ”stuck” should be delivered successfully!

Spara/återskapa körande Vagrant burkar vid avstängning/uppstart

Ett simpelt script som avslutar körande Vagrant burkar vid avstängning av din dator.

#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          something warm and fuzzy 
# Required-Start:    vboxdrv
# Required-Stop:     vboxdrv
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts suspended vagrant boxes and suspends running vagrant boxes
# Description:       
### END INIT INFO

# presumably only users with valid login shells are running vagrant boxes
validShells=$(cat /etc/shells | grep -v "#" | sed ':a;N;$!ba;s/\n/|/g')
userList=$(grep -E "$validShells" /etc/passwd | awk -F ':' ' { print $1 } ' | tr "\\n" " ")

case $1 in
  start)
    # loop thru every user
    for user in $userList; do
      # loop thru users suspended boxes
      for vm in $(su -c "vagrant global-status" $user 2>/dev/null | grep saved | awk ' { print $5 } '); do
        cd $vm >/dev/null
        su -c "vagrant up" $user
        su -c "vagrant status" $user > /dev/null # update global-status cache
      done
    done
  ;;
  stop)
    for user in $userList; do
      for vm in $(su -c "vagrant global-status" $user 2>/dev/null | grep running | awk ' { print $5 } '); do
        cd $vm > /dev/null
        su -c "vagrant suspend" $user
        su -c "vagrant status" $user > /dev/null # update global-status cache
      done
    done
  ;;
  status)
    for user in $userList; do
      echo "$user's vagrant box status"
      echo "------------------------------------------------------------------------"
      su -c "vagrant global-status 2> /dev/null" $user
      echo
      echo
    done
  ;;
  *)
    echo "Usage: $0 {start|stop|status}" >&2
    exit 1
  ;;
esac

exit 0

Installera med:

Redigera /etc/init.d/vagrant-boxes och klistra in ovanstående (eller ladda ner filen här). Sen kör du:

# update-rc.d vagrant-boxes defaults 99 01

99 är sekvensnumret, måste vara högre än det du har för Virtualbox (som använder 20, vilket är standard). Fungerar det exempelvis att spara boxarna vid avstängning men de inte startas igen vid start, dubbelkolla denna siffran. Andra siffran är i vilken ordning när du stänger av datorn, så 01 betyder att det är det första den gör (vilket kan vara bra).

Suspend/resume all Vagrant boxes on system shutdown/startup

So, we’ve been using Vagrant a lot lately at work, and one thing that bugged me was whenever i shutdown my computer, it wouldn’t because I forgot to suspend or halt my running Vagrant boxes before shutting down.

So, I wrote a simple init script that suspends all running boxes, nice and easy. It should handle multiple users also (I have not tested this thou).

#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          something warm and fuzzy 
# Required-Start:    vboxdrv
# Required-Stop:     vboxdrv
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts suspended vagrant boxes and suspends running vagrant boxes
# Description:       
### END INIT INFO

# presumably only users with valid login shells are running vagrant boxes
validShells=$(cat /etc/shells | grep -v "#" | sed ':a;N;$!ba;s/\n/|/g')
userList=$(grep -E "$validShells" /etc/passwd | awk -F ':' ' { print $1 } ' | tr "\\n" " ")

case $1 in
  start)
    # loop thru every user
    for user in $userList; do
      # loop thru users suspended boxes
      for vm in $(su -c "vagrant global-status" $user 2>/dev/null | grep saved | awk ' { print $5 } '); do
        cd $vm >/dev/null
        su -c "vagrant up" $user
        su -c "vagrant status" $user > /dev/null # update global-status cache
      done
    done
  ;;
  stop)
    for user in $userList; do
      for vm in $(su -c "vagrant global-status" $user 2>/dev/null | grep running | awk ' { print $5 } '); do
        cd $vm > /dev/null
        su -c "vagrant suspend" $user
        su -c "vagrant status" $user > /dev/null # update global-status cache
      done
    done
  ;;
  status)
    for user in $userList; do
      echo "$user's vagrant box status"
      echo "------------------------------------------------------------------------"
      su -c "vagrant global-status 2> /dev/null" $user
      echo
      echo
    done
  ;;
  *)
    echo "Usage: $0 {start|stop|status}" >&2
    exit 1
  ;;
esac

exit 0

Installation

Edit /etc/init.d/vagrant-boxes and paste the above script and save (or download it from here and save it to /etc/init.d/vagrant-boxes). On debian/ubuntu etc, run

# update-rc.d vagrant-boxes defaults 99 01

Number 99 is the sequence number and should be larger than (in my case Virtualbox number 20, which by the way is the default on Debian distros). The second number is the sequence when shutting down the computer. So, it might be good to do first of all.

SSH connections using ProxyCommand

Scenario, you have a bunch of servers on your LAN with no access to the internet and you want to be able to connect to them via a specific server.

In this case, all your servers you wan’t to connect to resolves to *.example.tld. Hence, *.example.tld in the Host line. You can of course have a single host here. Tips, if you do set Host to *.example.tld and then proxy via for example in.example.tld, it will not work (I don’t have an explanation). I opted simply to use another domain for the ”incomming connection” server.

Anyway, add lines similar to these to your ~/.ssh/config
 

Host *.example.tld
ProxyCommand ssh proxy.someother.tld 'nc -w 120 %h %p'

and you’re set!

Now when you ssh to server1.example.tld ssh will actually connect using the command ssh proxy.someother.tld 'nc -w 120 server1.example.tld'.

Pretty neat and very, very useful!

LibreOffice blanka utskrifter

Fick en kvart över på jobbet (läs 45 minuter) att ta tag i ett problem jag haft länge; nämligen att det inte gick att skriva ut från något av LibreOffice programmen.

Problemet yttrade sig i att utskriften startade, men inget kom ut förutom en blank sida. Körde man testsidor i CUPS skrev den ut och andra program fungerade finemang.

Lösningen på problemet fram till nu har varit att först skapa en PDF i LibreOffice och sen skriva ut den med Okular i KDE. Extremt bökigt, men eftersom jag så sälla skriver ut något har jag levt med det.

Ända tills… jag bytte skrivarspråk i LibreOffice från PDF till PostScript Nivå 3.

Kruxet är att du måste göra det som admin genom att köra:

sudo /usr/lib/libreoffice/program/spadmin

annars måste du ändra skrivarinställningar för varje dokument du vill skriva ut.

spadmin