Linux
Ubuntu 11.10 boot problem
Today i had a network issue on my system, so i tried rebooting my Ubuntu 11.10 server which acts like a router, firewall, DHCP and DNS server for my network. Turns out there was a rather big problem with Ubuntu 11.10 if you upgraded from a previous version.
It seems that in Ubuntu 11.10 the directory containing running processes information and lock files has changed, or well, it has for certain programs. This results in a system where certain daemons/programs expect to find sockets in /var/run, while they are present in /run, or vice versa.
This might result in a boot problem looking like this:
The first lines are not so important, what is important are the last two. It says:
|
1 2 |
unable to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket : connection refused
Waiting for network configuration... |
After that last one, you might get that it waits for another 60 seconds for network configuration, but it will get stuck in boot after that.
Luckily i had my 3G enabled phone close, so i could do some searching, which gave me a link to a bug report and a forum post with a fix. In short, few simple steps can help you out here:
- reboot into recovery mode
- start a root shell
- mount the filesystem as read/write:
1mount -o remount,rw / - move everything from /var/run into /run:
1mv /var/run/* /run/ - move /var/lock into /run:
1mv /var/lock /run/ - create symlinks from /var/run to /run and /var/run/lock to /var/lock:
12ln -s /run /var/runln -s /run/lock /var/lock - reboot
Worked like charm here. Hope this helps.
PHP 5.3.2 DateTime diff() issue
It seems that PHP 5.3.2 ( 5.3.2-1ubuntu4.10 ) has a small issue when using the DateTime diff() method.
Got this code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
< ?php
$mode = 'D';
$back = 1;
$start = new \DateTime();
$start->setTime(0, 0);
$start->sub(new \DateInterval('P'.$back.$mode));
$end = new \DateTime();
$end->setTime(0, 0);
if( $back > 0 ) {
$end->sub(new \DateInterval('P'.($back-1).$mode));
} else {
$end->add(new \DateInterval('P1'.$mode));
}
echo $start->format('Y-m-d H:i:s') . "\n";
echo $end->format('Y-m-d H:i:s') . "\n";
$dt = $start->diff($end);
echo $start->format('Y-m-d H:i:s') . "\n";
echo $end->format('Y-m-d H:i:s') . "\n";
$differenceDays = $dt->format('%a');
echo $differenceDays."\n";
?> |
This code results in:
2011-12-03 00:00:00 2011-12-04 00:00:00 2011-12-02 00:00:00 2011-12-04 00:00:00 2
It seems the diff statement changes the starting date to a date before. This is kind of an issue, i need that difference in a project between days, weeks, months and even years. And the issue get’s worse if you use weeks (the difference becomes 14 days instead of 7) in the interval or months (61 instead of 30 or 31). So i decided to use a quickfix to calculate the difference, cause this was not working…
The workaround needed to change depending on the mode variable (day, week, month or year). For day and week it could just be 1 and 7 days, but the amount of days in a month and years changes per month and per year (leap years). So i came up with:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
< ?php
switch($mode) {
case "day":
$differenceDays = 1;
break;
case "week":
$differenceDays = 7;
break;
case "month":
$differenceDays = date('t',$start->getTimestamp());
break;
case "year":
$differenceDays = 365;
if( date('L',mktime(0,0,0,1,1,$start->format('Y'))) == 1 ) {
$differenceDays++;
}
break;
}
?> |
I decided to use the mktime function, because the getTimestamp() gave some issues concerning timezones (i think ;))
Update
Dries Verachtert pointed me to a comment on the page of the DateTime sub method. The short of it:
If you use diff() after sub(), the effects of the sub() will be repeated on the date object.
It doesn’t matter if the object is the one diffed or doing the diffing (i.e. which object you call diff() from).
Note that using add() instead of sub() does NOT have the same effect.
This is particularly undesirable — in this example you make a datetime, use sub() to make it a relative time in the past, and then date->diff() to confirm the difference. But the diff() inadvertendly makes the difference 2x.
Strange issue, but i can tell you it’s fixed in 5.3.3, as i have running that on an internal test server, and the code does a perfect job on that.
Setting up a new VPS
Today i decided to get a new VPS from Shift to the cloud, a new project from Stone Internet Services (@stoneis). Stone IS has been a choice for webhosting and domain registration for me and my clients for years, and i have always been happy with their service.
In the past i have always counted on ULYSSIS for my personal hosting, as i have been vice-president of this organisation and have a free account because of that. But lately, i realized that, although their service is incredible for an organization of volunteers, it is not as open and free as having an own server at your disposal.
Ordering the server was rather easy, i only had an issue with the payment system, but i hope it was just a fluke and not something others experience. At least the service desk helped me out pretty quick. I opened an issue last night and it was fixed by the time i woke up this morning, on a Saturday.
After i got the base VM (Ubuntu 10.04 LTS) running i started to configure it by installing some base packages like apache, openssl, php5, suphp, … After a while i noticed it didn’t have the promised IPv6 address, so i opened another support ticket, and it took them about 15 minutes to fix it. If that’s an indication of response time for the Best Effort SLA, i am impressed.
When the IPv6 address was enabled, i did get into trouble with Apache. Everytime i wanted to start it, it crashed with the following error:
[Sat Dec 03 12:48:52 2011] [error] (9)Bad file descriptor: apr_socket_accept: (client socket)
Whenever i disabled SSL, it worked fine. After a few google searches, i came to the conclusion that the automatically generated SSL certificates became invalid with the change of network interfaces/addresses. I fixed that quickly by creating a new certificate, and my own Certificate Authority . If you need some info on how to do that, you can find a good tutorial on the website of Paul Bramscher.
And now that this blog is moved to the server, we’ll see how it goes. Next step will be to move my Symfony2 project from my development environment (VM on a personal vSphere setup on two local servers) to this server, so i can more easily access it from anywhere.
Other plans include setting up a monitoring system (Nagios) to monitor my internal network and some servers and environments of my smaller clients (who do not have the resources to implement it locally). This kind of monitoring system is already running on my local vSphere farm, but that means it uses my personal internet connection, which is just a commercial connection (once or twice a month it goes down in the middle of the night for 10-15 minutes).


