Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Tuesday, 4 April 2017

"Let your Daemons rest", aka PHP Daemons not sleeping as expected

I was enhancing some inherited PHP code which used the so-called "Daemon Loop" design pattern to read jobs off a queue and hand them off for processing by a configurable number of child worker processes. Specifically, I was trying to get the daemon to wake up once every minute (instead of every 5s) to see it there were any jobs on the queue, so in the loop (in practice the value was read from a config file into a class-level variable), I had:
    sleep(60)

We were also capturing SIGCHLD for notification of when the child closed (in this instance after just a few seconds).

The problem was that the daemon was not waiting 60s to poll unless there was nothing to do. Turns out that SIGCHLD cancels the running sleep(60).

My inelegant solution? sleep(1) 60 times and then only 1s of sleep is lost!
while ($sec>0) {
    sleep(1);
    $sec--;


Thanks to Stuporglue, on whose PHP daemon example code I built a testbed to find a solution.

Wednesday, 30 May 2012

Ubuntu apt-get - packages not found

We had a problem when installing a bespoke Ubuntu 10.04 Server LTS setup via shell scripts we had written. Some of the packages were not found. This mainly occurred on virtual dedicated servers. We had previously installed on more than 20 normal dedicated server ok.

Turns out that the /etc/apt/sources.list had only a very limited list on the ones that didn't work. I copied the file from a normal server that was ok, and re-tried our scripts. That solved the problem.

Not too sure if you could build up other problems doing this, so always save a copy of the original file somewhere safe before changing.

Examples follow after the break...

Friday, 23 March 2012

MySql Replication - Error 1045

Fighting with a simple test-bed MySql replication between 2 Ubuntu 10.04 LTS servers.

It turned out you need to use the domain name, not the IP address when specifying the MASTER_HOST in the following MySql command on the Slave:

CHANGE MASTER TO MASTER_HOST='192.168.0.100', MASTER_USER='[username]', MASTER_PASSWORD='[password]', MASTER_LOG_FILE='mysql-bin.NNNNNN', MASTER_LOG_POS=N;