Archive for the ‘Daemons’ Category

Compile lsyncd with Lua at special location

Friday, October 11th, 2013

The Situation

First we installed latest Lua (5.2.2) from source. We installed it into separate prefix: /usr/local/lua-5.2.2-1
Symlinks were made to point to actual locations from /usr/local/bin

The Symptoms

This symptom occured first:

It is BOGUS as anyone from the sky could see. (more…)

Restarting network with keepalived on RedHat / CentOS

Tuesday, October 8th, 2013


This was supposed to be a normal setup: highly-available gateways/firewall with CentOS and keepalived. Been there, done that, just not with CentOS. Anyway, I anticipated no problems whatsoever.

The Twist

The installation went smooth, firewall configuration was deployed from git from previous server, and so was keepalived.conf. Startup normal, things worked as expected. Then there was this thing with removing old statically-configured IP addresses from the system.
I edited appropriate files in /etc/sysconfig/network-scripts/, executed ‘service network restart’ and was cut off from the machine.


This almost never happened before on RH/CentOS. Ok, it did happen when I messed up the IP digits, or when I tried to restart only one interface (dunno exactly about this one, but machine was 200km away and I really did not feel like roadtrip so I just resorted to restarting whole network stack which seemed to work ATM).

Fortunately I had a backup network interface still reachable and thorough that I was able to restore connections and debug the situation.

The Reason

It turned out that keepalived was lagging a little bit behind actual system state and it tried to follow the network interface status changes, but it actually messed up the networking configuration.

Here is what should happen:

  1. ‘service network restart’ executed
  2. interfaces go down
  3. interfaces go up
  4. keepalived does its magic to assign correct HA IP addresses

Here is what actually happened:

  1. ‘service network restart’ executed
  2. interfaces go down
  3. interfaces go up
  4. as soon as interfaces get up, keepalived readds HA IP addresses
  5. primary IP address then gets assigned to the interface as secondary address
  6. keepalived receives higher-priority VRRP advertisement, and removes IP address from interface
  7. unfortunately this also removes should-be-primary IP address and leaves server with an IP-address-less interface and thus unreachable server

The Resolution

The resolution was simple: do not restart network when keepalived is running. To achieve that we needed to modify the /etc/init.d/network script which now notifies the admin that keepalived is running and refuses to continue in such situation.

Here is the diff of the changes we did: network-keepalived.diff

I hope no one else gets biten by this peculiarity. Or if she does, she does not spend hours trying to figure out where carnivorous animal is hiding :)

Standalone preforking PHP application server framework

Tuesday, August 18th, 2009

What a lenghty title! But it does characterize well the thing I have been working on a couple of nights.

The idea consists of these basic prerequisites:
– sometimes I need to create small application that is not a standard web application,
– it could be necessary that it it running as root/other privileged user,
– it probably receives client connections from network,
– I need to have total control of what it does, for security reasons,
– I do not want to configure it, I want to write it.
– I want it to be written in PHP, which is a commodity language.

Usually PHP is coupled with some web server software, which together then constitutes web application server. This is a standard setup. It involves installing a web server, like Apache or NginX or IIS etc, which then you have to configure to suit your needs. Then you have to add PHP to it, and configure that too.

But what if you do not want a WEB server, what if you want a CUSTOM application server that does not use HTTP protocol but some weird/invented/forgotten/X protocol that you find suitable for your purpose?

This is why I have written this framework. You do not have to start from scratch, if you do not want to. What it does is this:
– starts and daemonizes
– forks as many children as needed
– children start waiting for connections
– when connection arrives, one of the children accepts the connection
– here your custom processing part starts – you start by rewriting the $this->worker_handleClient() or $this->worker_handleRequest() method, like below:


And that is basically it. Framework handles the rest of the story, accepts multiple simultaneous connections, forks additional children, etc. There is still a lot to do but I managed to get first working daemon written in 10 minutes. It does fairly trivial job (accepting XML-RPC request and then su-ing to some specified user and running some shell command) but what seemed miles away once is now easily achieved.

If you need it, enjoy it. Here is the URI:
Standalone preforking PHP application server framework.

If you find some feature missing and/or you have prepared a patch for it, let me know in comments. Also, (constructive) critique is welcome.