OnWorks favicon

hapolicy - Online in the Cloud

Run hapolicy in OnWorks free hosting provider over Ubuntu Online, Fedora Online, Windows online emulator or MAC OS online emulator

This is the command hapolicy that can be run in the OnWorks free hosting provider using one of our multiple free online workstations such as Ubuntu Online, Fedora Online, Windows online emulator or MAC OS online emulator



hapolicy - policy delegation high availability script


hapolicy [OPTIONS] --service=SERVICE1 [--service=SERVICE2 ...]

-s, --service <name>=<address>:<port>[:<prio>:<weight>:<timeout>]

-d, --default <action> returns <action> if no service was available (default: 'dunno')
-l, --logging log requests
-v, --verbose increase logging verbosity
-L, --stdout log to stdout, for debugging, do NOT use with postfix


hapolicy enables high availability, weighted loadbalancing and a fallback action for
postfix policy delegation services. Invoked via postfix spawn it acts as a wrapper that
queries other policy servers via tcp connection. The order of the service queries can be
influenced by assigning a specific priority and weight to each service. A service is
considered 'failing', if the connection is refused or the specified service timeout is
reached. If all of the configured policy services were failing, hapolicy returns a default
action (e.g. dunno) to postfix.

With version 1.00 hapolicy has less than 200 lines of perl code using only standard perl
modules. It does not require any disk access nor configuration files and runs under an
unpriviledged user account. This should allow fast and reliable operation.

A service has the following attributes

"servicename" => {
ip => '', # ip address
port => '10040', # tcp port
prio => '10', # optional, lower wins
weight => '1', # optional, for items with same prio (weighted round-robin), higher is better
timeout => '30', # optional, query timeout in seconds

You may define multiple services at the command line. Which means that

hapolicy -s "grey1=" -s "grey2="

will always try first service grey1 at ip port 10031 and if that service is not
available or does not answer within the default of 30 seconds the next service grey2 at ip port 10031 will be queried.

If you want to load balance connections you may define

hapolicy -s "polw1=" -s "polw2="

which queries service polw1 at ip twice as much as service polw2 at ip
Note that this setup also ensures high availability for both services. If polw1 is not
available or does not answer within the default of 30 seconds polw2 will be queried and
vice versa. There is no reason to define a service twice.

Enter the following at the bottom of your postfix master.cf (usually located at

# service description, note the leading blanks at the second line inet n n n - 0 spawn
user=nobody argv=/usr/local/bin/hapolicy -l -s GREY1= -s GREY2=

save the file and open postfix main.cf. Modify it as follows: = 3600

smtpd_recipient_restrictions =
... other authed permits ...
... other restrictions ...
check_policy_service inet: # <- hapolicy query

Now issue 'postfix reload' at the command line. Of course you can have more enhanced
setups using postfix restriction classes. Please see "LINKS" for further options.


[1] Postfix SMTP Access Policy Delegation

[2] Postfix Per-Client/User/etc. Access Control

Use hapolicy online using onworks.net services

Free Servers & Workstations

Download Windows & Linux apps

  • 1
    Avogadro is an advanced molecular
    editor designed for cross-platform use
    in computational chemistry, molecular
    modeling, bioinformatics, materials
    science and ...
    Download Avogadro
  • 2
    XMLTV is a set of programs to process
    TV (tvguide) listings and help manage
    your TV viewing, storing listings in an
    XML-based format. There are utilities to
    Download XMLTV
  • 3
    Strikr Free Software project. Artifacts
    released under a 'intent based'
    dual license: AGPLv3 (community) and
    CC-BY-NC-ND 4.0 international
    Download strikr
  • 5
    giflib is a library for reading and
    writing gif images. It is API and ABI
    compatible with libungif which was in
    wide use while the LZW compression
    algorithm was...
    Download GIFLIB
  • 6
    With Hugin you can assemble a mosaic of
    photographs into a complete immersive
    panorama, stitch any series of
    overlapping pictures and much more..
    Audience: Sci...
    Download Hugin
  • 7
    Alt-F provides a free and open source
    alternative firmware for the DLINK
    DNS-320/320L/321/323/325/327L and
    DNR-322L. Alt-F has Samba and NFS;
    supports ext2/3/4...
    Download Alt-F
  • More »

Linux commands