My Galagzee!

Tech in a Galagzee, Not So Far Away.

Follow me on TwitterRSS Feeds

  • Home
  • Ville’s Ergonomics Recommendations
  • Archives

Mounting an NFS share after boot, and checking up on it periodically…

Jul 23rd

Posted by Ville Walveranta in Networking

No comments

I needed to automatically mount an NFS share after reboot. But the availability of that share could not be guaranteed – the system on the LAN offering the share might be down for maintenance when the system mounting the share is being rebooted. In such case there would be a lengthy wait during the boot sequence until the mount attempt would time out.

So I wrote a short script to handle the situation. When initialized at boot time through init.d or rc.d, it’ll first attempt to mount the share, but then times out in two seconds (this is a LAN NFS share so if the system offering the share is up there should not be a longer delay than that) and so the boot sequence is not slowed down terribly. (see update below) Once boot is complete, the script is run via cron every five minutes. Depending on the criticality of the share you may want to make that time shorter or longer. In this case it is a backup share which is not critical for the system’s functioning.

This technique would handle circular mounts, too, but obviously you would run into trouble if the mounts are required for successful system boot.

For this to work successfully add a marker file, such as “.myremoteservertransfers” in my example script below, in the share folder on the system exporting the share. I usually set the undeletable attribute on the file to make sure it doesn’t get accidentally deleted.

Update: Even with this code the boot sequence appears to hang until portmap times out (which takes quite a while) if the NFS share is not available at boot time. I removed the rc.d mount attempt and just shortened the cron poll period to 1 minute. That way the share will be up very quickly once it becomes available, yet the overhead caused by the periodic ping is minimal (both servers are on local LAN).

  |  copy code |? 
01
#!/bin/sh
02
 
03
SHELL=/bin/sh
04
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
05
 
06
# remote system name
07
remotesystem=myremoteserver
08
 
09
# remote share name
10
remoteshare=/nfsexports/backupshare
11
 
12
# local mount point
13
mountpoint=/localbackups/TRANSFERS/${myremoteserver}
14
 
15
# file to indicate local mount status
16
testfile=$mountpoint/.myremoteservertransfers
17
 
18
# --- end variables ---
19
 
20
# ping result to the remote system (2 sec timeout); not empty is OK
21
remoteping=`ping -c1 -o -q -t2 ${remotesystem} | grep " 0.0%"`
22
 
23
if [ "${remoteping}" != "" ] ; then
24
 
25
   # server is available so query availability of the remote share; not empty is OK
26
   offsiteshare=`showmount -e ${remotesystem} | grep "${remoteshare}"`
27
 
28
   if [ "${offsiteshare}" != "" ] ; then
29
      if [ ! -e ${testfile} ] ; then
30
         mount -r -t nfs ${remotesystem}:${remoteshare} ${mountpoint}
31
      fi
32
   fi
33
fi
34
 
35
exit 0

automatic, boot, circular, nfs

Caching inbound email on LAN with Postfix (and restricting reception of external mail only to the external mail provider)

Jul 10th

Posted by Ville Walveranta in Mail

No comments

Externalizing email reception often offers many benefits: firstly, it’s [more] worry-free than servicing email internally, especially in smaller organizations where there may not be an email administrator on-call 24/7. Or, think of a situation where there is an “IT guy” who manages internal email. Then he goes on a vacation and email goes down. Now what? And even when the IT guy is present, the budget may not allow for good redundancy for email reception. What if the email server melts down. Perhaps there is a backup plan but without a stand-by server and/or perhaps virtualization option getting mail reception back online could take a day, which potentially would be a big hindrance to business.

However, outsourced email is not without its pitfalls, too. Even with a reasonably fast network connection there is more noticeable latency when accessing a remote email server as opposed to a LAN-based solution. Then there is the issue of outsourced service quality vs. the cost. Some services like Fusemail or Rackspace offer reasonable quality and fairly customizable features. But when something does go wrong you’re dependent on their response time. You’ve essentially handed away control of your email reception, for better or for worse.

Mostly, however, reception uptime is good with most well-run outsourced mail services, and the issues that more commonly crop up are related to latency and in some cases (like with Fusemail from time to time) apparent capacity issues. And if you access Fusemail with Outlook 2010′s IMAP client, you may have noticed frequent spontaneously changing message ID’s which repeatedly pop up a notification on Outlook.

The client-side issues are easy to remedy by caching inbound email on your local server. It gives you the best of both worlds: quick access to email and safety of someone monitoring mail reception 24/7 with multiple redundancies. If your local caching mail server goes down even for an extended amount of time, all you need to do is to repoint your clients to the external provider’s IMAP or POP server and you’re back in business. You may also opt to use your own outbound SMTP service (assuming you have a static IP in use) which makes it possible to isolate your domains’ SPF records to the IPs you own (as opposed to allowing anyone with an account, for example, at Fusemail to spoof mail from your domains without an SPF penalty). And if you use Fusemail, your own SMTP server will give you a peace of mind so that your outbound emails won’t trigger suspension of your account like happened to me soon after I first signed up with them (see Fusemail auto-suspends spam-suspect accounts!). Perhaps they’ve fixed that issue since then.

Setting up a caching mail service on your LAN is fairly easy with Postfix. The following tutorial assumes you already have a functioning Postfix/Dovecot setup where you’re able to send and receive email based on your requirements.

To start with, configure and test local users that you would like to correspond to outsourced email service’s mailboxes. They do not need to have the same login name, and you can also consolidate multiple external accounts to one local account. In smaller setups it’s the easiest to simply create a flat-file for user Dovecot passwords lookups.

Assuming you like to receive all email through an outsourced service (which, if you use an outsourced service, is the preferred option), you will want to restrict mail reception from the outside world only to the sending mail servers of the external mail provider of your choice. To accomplish this some restrictions are added to the local cache server’s main.cf file. The following is the configuration I use; I’ve carefully given thought of the restrictions not being too constrictive as to unnecessarily prevent connections, but on the other hand cut off connections that would not result in a successful or desired mail transit.

  |  copy code |? 
01
02
smtpd_helo_restrictions =
03
        permit_mynetworks
04
        reject_invalid_helo_hostname
05
        permit_sasl_authenticated
06
        reject_non_fqdn_helo_hostname
07
 
08
smtpd_client_restrictions =
09
        permit_mynetworks
10
        permit_sasl_authenticated
11
        check_client_access hash:$config_directory/tables/smtpd_client_access
12
        check_client_access cidr:$config_directory/tables/smtpd_client_access.cidr
13
        reject
14
 
15
smtpd_etrn_restrictions =
16
        permit_mynetworks
17
        reject
18
 
19
smtpd_sender_restrictions =
20
        reject_non_fqdn_sender
21
        reject_unknown_sender_domain
22
 
23
smtpd_recipient_restrictions =
24
        reject_non_fqdn_recipient
25
        reject_unknown_recipient_domain
26
        permit_mynetworks
27
        reject_unlisted_recipient
28
        permit_sasl_authenticated
29
        check_recipient_access hash:$config_directory/tables/smtpd_recipient_access
30
        #the following also permits mynetworks!
31
        check_recipient_access pcre:$config_directory/tables/smtpd_recipient_access.pcre
32
        reject_unauth_destination
33
 
34
smtpd_data_restrictions =
35
        reject_multi_recipient_bounce
36
        reject_unauth_pipelining
37

You will notice external hash and PCRE lookup tables “smtpd_client_access”, “smtpd_client_access.cidr”, “smtpd_recipient_access”, and “smtpd_recipient_access.pcre”. Let’s look at them next.

smtpd_client_access (hash) and smtpd_client_access.cidr (example below) list the external IP addresses you allow to connect and hence relay mail to your cache server. If the external IPs are not on this list, the connection is terminated.

Here’s an example smtpd_client_access (hash, so it’s converted to smtpd_client_access.db with postmap):

  |  copy code |? 
1
2
# some individual external server I want to allow to connect
3
100.200.100.200 PERMIT
4

And here’s an example smtpd_client_access.cidr:

  |  copy code |? 
1
2
1.2.3.4/24      OK
3
10.20.30.40      OK
4
100.200.201.0/21      OK
5

While the sending servers of an outsourced service don’t change often, they may change at any time without a warning. Thus maintaining the above list manually would be a frustrating task. To automate the process, you can cull this information from the outsourced mail service’s SPF records with a cron-scheduled shell script (note that paths relate to FreeBSD; if you run Linux, adjust them to the taste/requirements):

  |  copy code |? 
01
02
#!/bin/sh
03
 
04
ORIGINAL=/usr/local/etc/postfix/tables/smtpd_client_access.cidr
05
NEW=/tmp/postfix_clients.tmp
06
 
07
dig +short fusemail.net TXT | grep 'v=spf1' | egrep -o 'ip4:[0-9./]+' | sed 's/^ip4://' | sed 's/$/      OK/' > $NEW
08
 
09
ORIGINAL_CK=`cksum $ORIGINAL | awk '{print $1}'`
10
NEW_CK=`cksum $NEW | awk '{print $1}'`
11
 
12
if [ -s $NEW ] ; then
13
  if [ $ORIGINAL_CK != $NEW_CK ] ; then
14
    cp -f $NEW $ORIGINAL
15
    postfix reload > /dev/null 2>&1
16
  fi
17
fi
18
 
19
rm $NEW
20
 
21
exit 0
22

The above example is obviously for Fusemail, but you can modify it for other providers simply by replacing the provider domain name on the dig line.

In my configuration smtpd_recipient_access (hash) lists simply the nullroute that is often required – such as in php.ini mail configuration where you might put:

sendmail_path = /usr/sbin/sendmail -t -i -f nullroute@mydomain.com

So in smtpd_recipient_access (hash) I list:

  |  copy code |? 
1
2
nullroute@mydomain.com  PERMIT
3

Meanwhile, smtpd_recipient_access.pcre lists the users who’re allowed to receive mail externally, from the IPs you defined with smtpd_client_access/smtpd_client_access.pcre:

  |  copy code |? 
1
2
if !/^(nullroute|abuse|postmaster|user1|user2|user3)@mydomain\.com$/
3
/^/ internal
4
endif
5

Again, the above is sufficient for small configurations, but if you have dozens or more users whose external email you’re caching you may be better off storing the client_access table on a database server.

Finally, as you notice the ‘internal’ keyword being added above to user addresses that are not matched by smtpd_client_access.pcre, you want to add the following in main.cf:

  |  copy code |? 
1
2
smtpd_restriction_classes = internal, public
3
internal = permit_mynetworks, reject
4
public = permit
5

With these in place you will now receive email only from your external mail provider (and perhaps some other authorized servers if you defined one with smtpd_client_access hash table). This is important because you’re likely using your outsourced mail provider’s spam filtering, and you don’t want spammers contacting your cache mail server directly.

With the local server configured (and hopefully sufficiently tested :) ) you can then go ahead and create mail forwarding rules at the external provider of your choice. You would simply copy any arrived email to the corresponding email address at your local cache server. I have additionally created a rule at the external provider which prunes the mailbox after given number of time since the users will not go through and delete read email there.

You may want to allow authenticated client access to your local users so that they can access their email via IMAP or POP remotely, and perhaps over the web (like via locally installed Squirrelmail). It is also a consideration that the email at the external provider will not be synced back – if users delete email from their locally cached mailbox it will not be deleted from the mailbox at the external provider, so under normal circumstances your cached email server should be the only access point for mail. But in an event of the server melt-down it is a minor inconvenience that the external provider’s mailbox would have older emails (that perhaps were deleted locally) in it – at least the users can continue to access email while you’re getting the caching server back online!

** NOTE: I’m using the current GA/Stable version of Postfix (2.7.0). If you’re using an older version, double-check that the configuration options I propose above are available before using them! This is one reason for why I prefer to use FreeBSD for mail; the ports version of Postfix is kept well up-to-date while CentOS/RHEL Postfix package is — as you would expect from an Enterprise Linux — currently at 2.3.3. You could compile it yourself, I suppose, but I’m not up to the task since I’m not a full-time Postfix admin.

caching, mail, postfix

Things I didn’t know about ESXi

Jun 6th

Posted by Ville Walveranta in Technical

No comments

I’m setting up a development server using vmware ESXi virtual server running CentOS 5.5 x64 and FreeBSD 8.0 x64. Currently, the second installation pass is in progress. Being fresh to ESX/ESXi there were couple of things I didn’t realize:

First (the reason for the reinstall), if there is plenty of hard drive space available, it’s good idea not to deplete it all for the sytem installations. I split a 1.3Tb RAID 5 array between the two operating systems until I realized that 1) you can’t shrink vmfs partitions and 2) by consuming all hard drive space one limits the flexibility of the system down the line. Let’s say you want to install a newer version of an operating system and decide to do a fresh install. You need space for it while you want to keep the old version around at least long enough to migrate settings and data over.

Second, while I was aware of that ESXi doesn’t offer console access beyond the “yellow and grey” terminal, I didn’t realize you have no access to the VM consoles, either. So, with CentOS or FreeBSD installed, the only way to access their consoles is via the vSphere client (someone correct me if I’m wrong — I wish I were as I’d like to have local console access to the guest OS’es).

Finally, VMware Go “doesn’t currently support ESXi servers with multiple datastores”. So if you have, say, a 3ware/LSI/AMCC RAID controller which isn’t currently supported under ESXi as a boot device but which you likely still want to use as a datastore, you’ll end up with at least two datastores. So vSphere is really the only way to go for VM management also for this reason (since LSI provides a vmware-specific driver, one may also be able to direct-connect the LSI RAID array to the VM without it being an ESXi datastore, but that’s not the configuration I’m looking for—the boot device is small and houses just ESXi while the VMs and their associated datastores are located on the array).

In the end everything’s working quite well. I like the flexibility virtualization offers.. and consolidation is useful even in a small environment (one dev machine is less than two or three dev machines :) ).

centos, esxi, freebsd, virtual, vmware

LaserJet P2015dn duplexing on Windows 7

Jun 5th

Posted by Ville Walveranta in Hardware

No comments

HP LaserJet P2015 models use “Universal” driver under Windows 7. When first installed, duplexing doesn’t work by default. This is a surprise for many who come from Windows XP environment where the dedicated drivers had P2015′s built-in duplexing availability turned on, of course, by default. In Windows 7, however, the duplexing selector for P2015 says by default: “Print on both sides (manually)”.

To enable P2012′s automatic duplexing on Windows 7 go to Devices and Printers, highlight the P2015, right click, and select Printer Properties from the context popup menu. Go to Device Settings tab and look for “Duplex Unit (for 2-Sided Printing)” option. It’s set to “Not Installed” by default. Change it to “Installed” and click on “OK”. Now when you go to Preferences when getting ready to print, the automatic (not “manually”) option is available on the Finishing tab, and automatic duplexing works.

Also if you use the excellent priPrinter utility, P2015 honors the “Double Sided” toggle on the Page Layout tab. Same goes for the “Double-sided” checkbox on FinePrint utility, and other applications that provide the option to turn automatic duplexing on or off.

duplexing, laserjet, P2015, windows 7

Adding graphics, comments to PDFs

Mar 5th

Posted by Ville Walveranta in Rants

No comments

I needed to fill out a PDF document today, date it, and sign it. It took me a good hour to accomplish the task as while the latest incarnation of Acrobat has custom stamp feature, annotated text doesn’t print by default (I also wanted to avoid having to print out the document only to scan it back in). In fact, I found no way to print text annotations. Whether “Documents and Stamps” was selected in the Print properties or not, the text annotations would remain missing from the printout. It should not be this difficult to add a text box to a PDF document and then flatten it to be part of the document, and not an annotation per se.

After some more Googling later I happened on this page that outlines a simple way to add “flatten” options to the Acrobat document menu. The associated script to be placed in “Program Files/Adobe/Acrobat 9.0/Acrobat/Javascripts/” folder (the script works with older Acrobat versions, too, as the mentioned instructions are for Acrobat 7.0) is just two lines long:

  |  copy code |? 
1
2
app.addMenuItem({ cName: "Flatten page", cParent: "Document", cExec: "flattenPages(this.pageNum)",cEnable: 1, nPos: 16});
3
app.addMenuItem({ cName: "Flatten document", cParent: "Document", cExec: "flattenPages()",cEnable: 1, nPos: 17});
4

With the above script installed, the task was a snap: I added my signature from a transparent PNG as a custom stamp, added the text annotations, and then flattened the document. Done! Now the annotations print out as they should (whether or not “Documents and Stamps” is selected in the Print properties as now the annotations are part of the ‘base’ document). I can’t imagine why Adobe doesn’t include “flatten” as a default feature!

Acrobat, flatten, PDF, stamp
12345»10...Last »
Mystique theme by digitalnature | Powered by WordPress
RSS Feeds XHTML 1.1 Top