Administrera sin Telia router Thomson TG789vn från Internet

Om du har ADSL bredband från Telia så har du antagligen en Thomson TG789vn router därhemma. Jag har en sådan och har letat efter ett sätt att kunna administrera den över Internet då jag inte är hemma. Det verkar tyvärr inte finnas stöd för detta i routerns Telia-strypta programvara.

TG789vn

Ett sätt att komma runt detta är att man sätter upp en reverse proxy. I ‘mitt fall så löste jag det genom att använda mod_proxy i den apache webbserver som jag har igång hemma och som är öppnad (port forward port 80) mot Internet. Utöver det så har jag ett dynamiskt domän-namn kopplat mot servern.

Så här gick jag till väga:

1. Först skapade jag en egen subdomän kallad http://router.dindomän.com och pekade den mot servern.

2. Kollade så att apache har mod_proxy enablat i /usr/local/etc/apache22/httpd.conf

LoadModule proxy_module libexec/apache22/mod_proxy.so
LoadModule proxy_http_module libexec/apache22/mod_proxy_http.so
LoadModule xml2enc_module     libexec/apache22/mod_xml2enc.so
LoadFile   /usr/local/lib/libxml2.so
LoadModule proxy_html_module  libexec/apache22/mod_proxy_html.so

2. Skapade en användare för att lösenordsskydda routern. Username nedan är användarnamnet, lösenordet skriver man på förfrågan.

 htpasswd -c /usr/local/etc/router.user username

3. Lade in följande i apaches configurationför virtualhosts i /usr/local/etc/apache22/extra/httpd-vhosts.conf. 192.168.1.1 är den IP-adress som routern har på hemma-nätverket. Routern skyddas av BASIC-autentisering.

<Virtualhost *>
  ServerName router.domainname.com
  ProxyRequests Off
  <Proxy *>
     Order deny,allow
     Allow from all
    AuthType Basic
    AuthName "Password Required"
    AuthUserFile  /usr/local/etc/router.user
    Require valid-user
  </Proxy>

    ProxyPass / http://192.168.1.1/
    ProxyPassReverse / http://192.168.1.1

 </Virtualhost>

4. Starta om apache och besök webbsidan http://router.dindomän.com. Thomson boxens admin-sida bör nu dyka upp efter att du matat in användarnamn och lösenord.

Det var alles, happy administration!

Segmentation fault: 11 (core dumped) in php on Freebsd

Oh, I finally got time for some coding and server updates. Sadly but interestering I got this strange error after updating php5 (/usr/ports/lang/php5) to the latest in the Freebsd ports tree.

The error:
/usr/local> php -v
PHP Fatal error: PHP Startup: apc_shm_create: shmget(0, 31457280, 914) failed: Cannot allocate memory. It is possible that the chosen SHM segment size is higher than the operation system allows. Linux has usually a default limit of 32MB per segment. in Unknown on line 0
PHP Fatal error: PHP Startup: apc_shm_attach: shmat failed: in Unknown on line 0
Segmentation fault: 11 (core dumped)

The first problem was the ”PHP Fatal error” lines that has something to do with APC cache. This was solved by:
/usr/ports/www/pecl-APC> make config
Then I unticked the "IPC Enable IPC shm memory support (default: mmap)" line. Don't really know what it does....
/usr/ports/www/pecl-APC> make deinstall
/usr/ports/www/pecl-APC> make clean
/usr/ports/www/pecl-APC> make install clean

The second problem was the ”Segmentation fault: 11 (core dumped)” line which caused a core dump each time php ran (a php.core file is produced). This was a bit strange. To investigate why it crashes I used gdb on the core file. A core file contains the in-memory state of the program at the time it crashes.

/usr/local/lib/php> gdb /usr/local/bin/php php.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
Core was generated by `php'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libcrypt.so.4...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypt.so.4
Reading symbols from /usr/local/lib/libpcre.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpcre.so.0
Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.5
Reading symbols from /usr/local/lib/libxml2.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxml2.so.5
Reading symbols from /lib/libz.so.4...(no debugging symbols found)...done.
Loaded symbols for /lib/libz.so.4
Reading symbols from /usr/local/lib/libiconv.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libiconv.so.3
Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.7
Reading symbols from /usr/local/lib/php/libs/curl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/curl.so
Reading symbols from /usr/local/lib/libcurl.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libcurl.so.6
Reading symbols from /usr/lib/libssl.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libssl.so.5
Reading symbols from /lib/libcrypto.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypto.so.5
Reading symbols from /usr/local/lib/php/libs/iconv.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/iconv.so
Reading symbols from /usr/local/lib/php/libs/json.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/json.so
Reading symbols from /usr/local/lib/php/libs/exif.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/exif.so
Reading symbols from /usr/local/lib/php/libs/ftp.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/ftp.so
Reading symbols from /usr/local/lib/php/libs/openssl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/openssl.so
Reading symbols from /usr/local/lib/php/libs/hash.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/hash.so
Reading symbols from /usr/local/lib/php/libs/bz2.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/bz2.so
Reading symbols from /usr/lib/libbz2.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libbz2.so.3
Reading symbols from /usr/local/lib/php/libs/mysql.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/mysql.so
Reading symbols from /usr/local/lib/php/libs/tokenizer.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/tokenizer.so
Reading symbols from /usr/local/lib/php/libs/simplexml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/simplexml.so
Reading symbols from /usr/local/lib/php/libs/xml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xml.so
Reading symbols from /usr/local/lib/php/libs/posix.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/posix.so
Reading symbols from /usr/local/lib/php/libs/dom.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/dom.so
Reading symbols from /usr/local/lib/php/libs/gd.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/gd.so
Reading symbols from /usr/local/lib/libt1.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libt1.so.5
Reading symbols from /usr/local/lib/libfreetype.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libfreetype.so.9
Reading symbols from /usr/local/lib/libX11.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libX11.so.6
Reading symbols from /usr/local/lib/libXpm.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXpm.so.4
Reading symbols from /usr/local/lib/libpng.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpng.so.6
Reading symbols from /usr/local/lib/libjpeg.so.11...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libjpeg.so.11
Reading symbols from /usr/local/lib/libxcb.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxcb.so.2
Reading symbols from /usr/lib/librpcsvc.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/librpcsvc.so.4
Reading symbols from /usr/local/lib/libXau.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXau.so.6
Reading symbols from /usr/local/lib/libXdmcp.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXdmcp.so.6
Reading symbols from /usr/local/lib/libpthread-stubs.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpthread-stubs.so.0
Reading symbols from /usr/local/lib/php/libs/xmlreader.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlreader.so
Reading symbols from /usr/local/lib/php/libs/xmlwriter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlwriter.so
Reading symbols from /usr/local/lib/php/libs/sockets.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/sockets.so
Reading symbols from /usr/local/lib/php/libs/zlib.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/zlib.so
Reading symbols from /usr/local/lib/php/libs/session.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/session.so
Reading symbols from /usr/local/lib/php/libs/soap.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/soap.so
Reading symbols from /usr/local/lib/php/libs/xsl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xsl.so
Reading symbols from /usr/local/lib/libexslt.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libexslt.so.8
Reading symbols from /usr/local/lib/libxslt.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxslt.so.2
Reading symbols from /usr/local/lib/libgcrypt.so.17...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libgcrypt.so.17
Reading symbols from /usr/local/lib/libgpg-error.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libgpg-error.so.0
Reading symbols from /usr/local/lib/libintl.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libintl.so.9
Reading symbols from /usr/local/lib/php/libs/sqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/sqlite.so
Reading symbols from /usr/local/lib/php/libs/pdo.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/pdo.so
Reading symbols from /usr/local/lib/php/libs/pdo_sqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/pdo_sqlite.so
Reading symbols from /usr/local/lib/libsqlite3.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libsqlite3.so.8
Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/libthr.so.3
Reading symbols from /usr/local/lib/php/libs/xmlrpc.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlrpc.so
Reading symbols from /usr/local/lib/php/libs/ctype.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/ctype.so
Reading symbols from /usr/local/lib/php/libs/fileinfo.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/fileinfo.so
Reading symbols from /usr/local/lib/php/libs/filter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/filter.so
Reading symbols from /usr/local/lib/php/libs/imap.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/imap.so
Reading symbols from /usr/local/lib/libc-client4.so.9...done.
Loaded symbols for /usr/local/lib/libc-client4.so.9
Reading symbols from /usr/lib/libpam.so.4...done.
Loaded symbols for /usr/lib/libpam.so.4
Reading symbols from /usr/local/lib/php/libs/mbstring.so...done.
Loaded symbols for /usr/local/lib/php/libs/mbstring.so
Reading symbols from /usr/local/lib/libonig.so.1...done.
Loaded symbols for /usr/local/lib/libonig.so.1
Reading symbols from /usr/local/lib/php/libs/sqlite3.so...done.
Loaded symbols for /usr/local/lib/php/libs/sqlite3.so
Reading symbols from /usr/local/lib/php/libs/zip.so...done.
Loaded symbols for /usr/local/lib/php/libs/zip.so
Reading symbols from /usr/local/lib/php/libs/apc.so...done.
Loaded symbols for /usr/local/lib/php/libs/apc.so
Reading symbols from /usr/lib/librt.so.1...done.
Loaded symbols for /usr/lib/librt.so.1
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
#0 0x0000000805de1f5d in apc_sma_init () from /usr/local/lib/php/libs/apc.so
[New Thread 0x801533120 (LWP 100263)]

Ok, I smell some fish here. Then i checked the ”stack backtrace” with bt.

(gdb) bt
#0 0x0000000804c7c8c0 in ?? ()
#1 0x00000008042e1bc4 in xsltUnregisterExtModuleFunction () from /usr/local/lib/libxslt.so.2
#2 0x00000008040adc97 in zm_shutdown_xsl () from /usr/local/lib/php/libs/xsl.so
#3 0x000000000055e2cf in module_destructor ()
#4 0x000000000056597a in zend_hash_apply_deleter ()
#5 0x0000000000565be8 in zend_hash_graceful_reverse_destroy ()
#6 0x00000000005596f7 in zend_shutdown ()
#7 0x00000000005045f5 in php_module_shutdown ()
#8 0x00000000005e505f in main ()
#9 0x00000000004189e5 in _start ()
#10 0x0000000800786000 in ?? ()

The problem was clearly related to one of my php-extensions /usr/local/lib/php/libs/xsl.so. Then I tried not to use this extension by uncomment it in /usr/local/etc/php/extensions.ini. However I got similiar error in another extension by doing that. There must be some other error that hasn’t with my extensions to do…

With some google fu I found this post which explains the problem. Some extensions are threaded while php5 isn’t by default. To make php threaded you have to configure it to be so. That’s fairly easy in Freebsd.

/usr/ports/lang/php5/make config
Tick the "LINKTHR Link thread lib (for threaded extensions)" option.
/usr/ports/lang/php5/make deinstall
/usr/ports/lang/php5/make clean
/usr/ports/lang/php5/make install clean

Then i restarted my apache server, typed ”php -m” and everything looked fine, not one single strange error message. Yieeehaa!!

Problem adding old gmirror drive to current setup

I am running gmirror software raid in FreeBSD and it works great. Today I wanted to add another hard-drive to the server (not raided). After installing the hard drive and when I booted the system it didn’t start. All I got was a prompt and a message that said ”Manual root filesystem specification” like this:

Manual root filesystem specification:
    :  Mount  using filesystem 
             e.g. ufs:/dev/da0s1a
    ?                  List valid disk boot devices
           Abort manual input

  mountroot> 

What to do? Well, I couldn’t mount my gmirror but I could mount one of the drives in my gmirror setup. After some trial and error I remembered that I used the ”new” drive previously in another gmirror raid on another server. The disk therefore had gmirror metadata on it that had survived, so somehow that disk took over my normal raid. The metadata survives most disk actions like formatting, partitioning and such…

The gmirror utility uses on-disk metadata (stored in the provider's last sec-
tor) to store all needed information.

I had to run ”gmirror clear /dev/ad2” (ad2 is the new drive) to remove the metadata from the disk. After that I only had to reboot and the normal raid took over again. It took me some time to solve this very frustrating problem. The solution is pretty simple but there aren’t very much gmirror documentation on the web.

Strange behaviour when my gmirror raid lost one of the disks

To begin with, I really like the gmirror software raid feature in Freebsd. It has helped me to keep my server and my sistes online for a very long time without any large interruption. Since my last strange gmirror problem I haven’t had any problem until now. I checked my log and found out that my raid was DEGRADED, there were only one disk in my raid setup.

The error message was the following. Looks like some kind of disk failure…

Dec 21 22:30:14 kernel: ad6: TIMEOUT - WRITE_DMA48 retrying (1 retry left) LBA=693151663
Dec 21 22:30:24 kernel: ad6: TIMEOUT - WRITE_DMA48 retrying (0 retries left) LBA=693151663
Dec 21 22:30:24 kernel: ad6: FAILURE - WRITE_DMA48 timed out LBA=693151663
Dec 21 22:30:24 kernel: GEOM_MIRROR: Request failed (error=5). ad6[WRITE(offset=354893651456, length=114688)]
Dec 21 22:30:24 kernel: GEOM_MIRROR: Device gm0: provider ad6 disconnected.

However the disk was there and it was ok and I didn’t know why it had been disconnected. I tried the following set of commands:

root@server ~>gmirror deactivate -v gm0 ad6
gmirror: No such provider: ad6.
root@mysql ~> gmirror forget -v gm0
Done.
root@mysql ~> gmirror insert -v gm0 ad6
Done.
root@mysql ~> gmirror status
      Name    Status  Components
mirror/gm0  DEGRADED  ad4
                      ad6 (0%)

Then it started rebuilding at once, very strange. And it works as before again! Maybe this was a warning sign that the disk is going bad or was it some kind of glitch?

How to monitor hard drive temperature with MRTG and FreeBSD

I really love to monitor my servers, so why shouldn’t I also monitor the temperatures of my hard drives? In my mind a cooler hard drive lives longer than a hot one. However, the google paper on failure trends of hard drives says that the hard drive temperatures doesn’t have an impact on a hard drives life length. But I want things to run cool in my server so here is how I monitor the hard drives with mrtg and FreeBSD.

To be able to get the hard drives temperatures we have to install SmartMonTools.

The smartmontools package contains two utility programs (smartctl and smartd) to control and monitor storage systems using the Self-Monitoring, Analysis and Reporting Technology System (SMART) built into most modern ATA and SCSI harddisks. In many cases, these utilities will provide advanced warning of disk degradation and failure.

Install SmartMonTools
# cd /usr/ports/sysutils/smartmontools
# make install clean

Check the temperature of the drives that you want to monitor
# smartctl -a /dev/ad4 | grep Temperature_Celsius
194 Temperature_Celsius 0x0022 113 103 000 Old_age Always – 34
# smartctl -a /dev/ad6 | grep Temperature_Celsius
194 Temperature_Celsius 0x0022 148 091 000 Old_age Always – 30

Create a script called disktemp.sh that outputs the temperatures in a Mrtg friendly way.

#!/bin/sh
/usr/local/sbin/smartctl -a /dev/ad6 | grep Temperature | awk '{print $10}' | tail -n 1
/usr/local/sbin/smartctl -a /dev/ad4 | grep Temperature | awk '{print $10}' | tail -n 1
echo "A long time"
echo ""

Then create a mrtg cfg file called disktemp.cfg:

### Global Config Options
WorkDir: /home/www/mrtg
Options[_]: growright, bits
EnableIPv6: no
Language: swedish

# Sysload
Target[disktemp]: `/usr/local/etc/mrtg/disktemp.sh`
MaxBytes[disktemp]: 100
Options[disktemp]: integer,gauge,nopercent
YLegend[disktemp]: Temp (C)
ShortLegend[disktemp]: (C)
Legend1[disktemp]: /dev/ad4
Legend2[disktemp]: /dev/ad6
LegendI[disktemp]: /dev/ad4
LegendO[disktemp]: /dev/ad6
Title[disktemp]: Hard drive Temperature
PageTop[disktemp]: 

Hard drive temperature

Run mrtg (a couple of times)
/usr/local/bin/mrtg /usr/local/etc/mrtg/disktemp.cfg

Check If everything seems to be working. If OK then add this to crontab…

The result should be looking like this (in your language):

How to monitor cpu temperature with MRTG on FreeBSD

Have you ever wanted to monitor the cpu temperature on your server with MRTG and FreeBSD? Of course you wanted that if you have a server running in a closet or some other special place. By following my steps you can have a nice graph like below. It is really relaxing to have all vital stats from your server available online.

This small tutorial works if you have the same processor as I have (Athlon 64). The only thing besides MRTG that you need is the k8temp program which is described as ”k8temp is a utility to read the temperature sensors provided by AMD K8 and K10 processors, including most Athlon 64’s and Opterons.” If you don’t have a Athlon 64 cpu there are other programs that should be ok to get the temperature as well.

You should have MRTG installed and be somewhat familiar the concept to get this working…

Check your cpu (if you dont have a clue)
> dmesg | grep Processor
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 5000+ (2599.72-MHz K8-class CPU)

Install k8temp
> cd /usr/ports/sysutils/k8temp/
> make install clean

Then setup mrtg to use k8temp. This is my mrtg-config file: cputemp.cfg

### Global Config Options
WorkDir: /home/www/mrtg
Options[_]: growright, bits
EnableIPv6: no
Language: swedish

# Sysload
Target[cputemp]: `/usr/local/etc/mrtg/cputemp.sh`
MaxBytes[cputemp]: 100
Options[cputemp]: integer,gauge,nopercent
YLegend[cputemp]: Temp (C)
ShortLegend[cputemp]: (C)
Legend1[cputemp]: CPU 0:1
Legend2[cputemp]: CPU 0:2
LegendI[cputemp]: CPU 0:1
LegendO[cputemp]: CPU 0:2
Title[cputemp]: CPU Temperature
PageTop[cputemp]: 

CPU temperature

By running the ”k8temp” program you get a list of available sensors. Find the temperatures that you are interested in and edit the script below. This is the script ”cputemp.sh” that the mrtg-config-file uses to get the cpu-temperature:

#!/bin/sh
/usr/local/sbin/k8temp -n 0:0:1
/usr/local/sbin/k8temp -n 0:1:1
echo ""
echo ""

Run mrtg (a couple of times)
/usr/local/bin/mrtg /usr/local/etc/mrtg/cputemp.cfg

Check If everything seems to be working. If OK then add this to crontab…

Sending email in FreeBSD with Gmail

When I moved my mail functionality (Qmail) from my FreeBSD-server to Google Apps I was left with no way to send email from my server (sendmail disabled and gmail removed) from shell. I have no longer the need to recieve email from my server, thanks to Google! However, I needed to send emails from my server to report server status and report software/hardware errors.

This is how I solved the problem on my FreeBSD 7.0 server. I have verified that it also works on 9.1

1. Freebsd has a guide for setting up send only with ssmtp. First you should install ssmtp.

cd /usr/ports/mail/ssmtp/ && make install replace clean

2. Then you need to configure ssmtp for Gmail. Create this file in /usr/local/etc/ssmtp/ssmtp.conf. Replace email and password with your Gmail-account settings.

root=youremail@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=youremail@gmail.com
AuthPass=yourpassword
UseSTARTTLS=YES
rewriteDomain=gmail.com

3. Test ssmtp. First you have to create a textfile with the message that you are going to send. Copy the text between the lines below.

Save the text to ”testmessage.txt”.
————————–
To: youremail@gmail.com
From: youremail@gmail.com
Subject: Testmessage

This is a test
————————–

Then run this command to send the testmessage.

ssmtp -v youremail@gmail.com < testmessage.txt

You should see the following output:

[<-] 220 mx.google.com ESMTP 14sm2982172ewy.10 [->] EHLO mysql
[<-] 250 PIPELINING [->] STARTTLS
[<-] 220 2.0.0 Ready to start TLS [->] EHLO servername
[<-] 250 PIPELINING [->] AUTH LOGIN
[<-] 334 VXNlcm5hbWU6 [->] bWFyY3VzLm55YkBnbWFpbC5jb20=
[<-] 334 UGFzc3dvcmQ6 [<-] 235 2.7.0 Accepted [->] MAIL FROM:
[<-] 250 2.1.0 OK 14sm2982172ewy.10 [->] RCPT TO:
[<-] 250 2.1.5 OK 14sm2982172ewy.10 [->] DATA
[<-] 354 Go ahead 14sm2982172ewy.10 [->] Received: by Servername (sSMTP sendmail emulation); Tue, 09 Mar 2010 12:53:14 +0100
[->] From: "Username"
[->] Date: Tue, 09 Mar 2010 12:53:14 +0100
[->] To: youremail@gmail.com
[->] Subject: Testmessage
[->]
[->] This is a test
[->] .
[<-] 250 2.0.0 OK 1268135596 14sm2982172ewy.10 [->] QUIT
[<-] 221 2.0.0 closing connection 14sm2982172ewy.10 If everything seems ok you should now have a fresh email in your Gmail account. Check it out! If not, then you should probably check your ssmtp.conf file and verify that you can connect to smtp.google.com 4. Last, replace sendmail with ssmtp. This makes ssmtp the default mailer for your system. mv /usr/sbin/sendmail /usr/sbin/sendmail.org
ln -s /usr/local/sbin/ssmtp /usr/sbin/sendmail

5. Check that mail is working.

mail -v -s "TestSubject" youremail@gmail.com
Testing and
.

Output:
[<-] 220 mx.google.com ESMTP 16sm3004137ewy.7 [->] EHLO mysql
[<-] 250 PIPELINING [->] STARTTLS
[<-] 220 2.0.0 Ready to start TLS [->] EHLO servername
[<-] 250 PIPELINING [->] AUTH LOGIN
[<-] 334 VXNlcm5hbWU6 [->] bWFyY3VzLm55YkBnbWFpbC5jb20=
[<-] 334 UGFzc3dvcmQ6 [<-] 235 2.7.0 Accepted [->] MAIL FROM:
[<-] 250 2.1.0 OK 16sm3004137ewy.7 [->] RCPT TO:
[<-] 250 2.1.5 OK 16sm3004137ewy.7 [->] DATA
[<-] 354 Go ahead 16sm3004137ewy.7 [->] Received: by mysql (sSMTP sendmail emulation); Tue, 09 Mar 2010 13:11:41 +0100
[->] From: ”Username”
[->] Date: Tue, 09 Mar 2010 13:11:41 +0100
[->] To: youremail@gmail.com
[->] Subject: TestSubject
[->]
[->] testing
[->] .
[<-] 250 2.0.0 OK 1268136703 16sm3004137ewy.7 [->] QUIT
[<-] 221 2.0.0 closing connection 16sm3004137ewy.7 6. Check the log file. cat /var/log/maillog

Output:
SMTP[755]: Creating SSL connection to host
sSMTP[755]: SSL connection using RC4-MD5
sSMTP[755]: Sent mail for username@servername(221 2.0.0 closing connection 14sm3068161ewy.2) uid=0 username=username outbytes=696
sSMTP[1234]: Creating SSL connection to host
sSMTP[1234]: SSL connection using RC4-MD5
sSMTP[1234]: Sent mail for username@servername (221 2.0.0 closing connection 16sm3004137ewy.7) uid=0 username=username outbytes=349

Summary
This worked for me straight out of the box. I didn’t need to make any changes to make it work. I hope it works for you as well!

Hemsida till Ludvig Nordström sällskapet

Jag har nyligen hjälp en kompis med att bygga en hemsida åt Ludvig Nordström sällskapet. Så kika på den!

ludvig1

Eftersom jag är ett stort fan av att använda WordPress (php) som CMS till enklare webbsidor åt föreningar/mindre företag så blev det givetvis den tekniska lösningen. Som vanligt blev det lite hackande i form av att mixtra med teman samt plugins/tillägg men det var ganska enkla fixar som behövde göras. Samtidigt var det kul att se alla bra nyheter i WordPress 2.8. Det är riktigt imponerande att följa WP’s utveckling.

GEOM_MIRROR: Component ad2 (device gm0) broken, skipping

Another day for me with server trouble. On my server I use the Freebsd gmirror (software raid) with mirrored disks. It has worked perfectly for the last couple of years, however today I found out that my gmirror raid1 was degraded. The ”gmirror list” command told me that one of my disks was missing in the raid. The error message in /var/log/messages was the somewhat strange ”GEOM_MIRROR: Component ad2 (device gm0) broken, skipping”. Is my disk (ad2) bad or what? Why is gm0 broken? The disk is actually running and seems to be okey.

I found a solution for the problem. If you remove the ”missing disk” from the raid and then insert it again, then the raid is rebuilt. For me the raid seems to be working again.

My solution:
gmirror deactivate -v gm0 ad2
gmirror forget -v gm0
gmirror insert -v gm0 ad2

mod_rewrite: could not init rewrite log lock in child

I found this strange error in my freebsd Apache error log: ”mod_rewrite: could not init rewrite log lock in child”. The same error was logged every second and was filling up my disk with junk. This should not happen because I have a fresh installation of Apache from the Freebsd ports tree and no strange configuration.

After some google-time I found the ”RewriteLog directive” at the mod_rewrite page. It says: ”To disable logging either remove or comment out the RewriteLog directive or use RewriteLogLevel 0! ”

I set ”RewriteLogLevel 0” in my apache conf-file and restarted apache. The problem was now gone! I do not know which file or directory that mod_rewrite tries to write to however i am pleased to know that the problem was solved.