Category: Programming

The new server

I’ve been managing a server for 3 years in a data-park. That time we had a small project that was made in Ruby on Rails (it was a pilot project). Rails deployment wasn’t so easy, however these days there are good solutions with apache and nginx specific passenger module. So we didn’t have any choice, we invested into a machine and took it to a Data park. After the work I stayed alone, and the management of the server stayed on me. Currently it’s hosting five sites with email and domain services.

It’s running Gentoo, the reason is I like specifying those features of a software that I would like to use (I don’t need graphical extension for git with x11-common package on a webserver), and other package managers usually try to find out what I should need (and usually it doesn’t succeed). The drawbacks are compile and install all the necessary packages are very-very slow, and you need to have a gcc or g++, which causes security problems.

As I mentioned, the machine has been working for 3 years, so I decided to change it (although it’s configuration would be enough, but change the whole system without any longtime stop is not so trivial). My new configuration is (thx for Imi @ Balabit!):

  • Intel Core2Quad Q9300 2500 Mhz
  • Intel DG45ID motherboard (it’s a desktop board)
  • 4 x 2Gb Kingmax memory slots
  • 2 x 500Gb Seagate Raid edition disk, ST3500320NS
  • Chieftec BH01BBB400 box

After a lot of tests I decided it would run Debian, but exactly it’s only the base of the system. The system contains lightly separated racks, where each rack has one specified function, but share some common resources with each other. I’m going to write more about the construction of racks, by the way of the introduction they are simple chroot environments managed by Gentoo’s package manager, Portage.

You can ask me why Debian, why not Ubuntu or Gentoo. I’d like to build a thin layer, which handles only the hardware and the basic system tasks. I’d like to create a system in an hour and not in a day. I guess Ubuntu is rather a desktop instead of a server operating system. Ubuntu has the newest packages of a software, but in a server I prefer security to the rapid package building.

So, I chose software raid, I didn’t want to pay a lot of bucks for a hardware raid. I can have problems at blackout, but in a Data park it is very rare.

So my partitions:

  • 150Mb /boot, ext2 (RAID1)
  • 8Gb Swap | /tmp (sda|sdb)
  • 5G / , XFS (RAID1)
  • 453G logical partition with raid1 and lvm

Different partitions on lvm:

  • /usr XFS
  • /var XFS
  • /backup XFS (for local backups)
  • /racks XFS (storage for the racks, it’s comming later)
  • /home XFS (with quota support)

I wasn’t so brave to take the / partition to a logical volume, but I hope 5G will be enough (although we know Bill Gates’ famous phrase about memory consumption)

I’ve installed the following software to the base system (without editors and other non-important stuffs):

  • sshd (remote management with chroot support)
  • mdadm (raid management)
  • smartmontools (monitoring hard disks)
  • syslog-ng (for logging)
  • git (version control for /etc and rack manager software)
  • backup-manager (creating backup from /etc and the racks’ rw partitions (later) with remote upload support)
  • jailkit ( I’ve built a debian package in a buildd debootstrap environment because I found it only in source version, however it’s a very good tool to build and manage chroot environments)
  • python (for jailkit and for my rack manager)
  • aufs (for the rack environment, but I’m thinking about funionfs because aufs is a kernel module while funionfs is running in user-space by fuse. So at a crash only the fuse dies, not the whole system.)
  • squashfs (for creating racks and snapshots)

The rack system will be in the next part…

Protected methods in objective-c

In objective-c there is no language supported solution for private and protected class methods as in C++ or Java. The reason is Objective-c is only a layer on the language C which is (as it is known) not an object oriented langauge. The @protected and @private tags are only directives for the compiler to throw an error when other objects call methods in their scopes.

This compiler directives unfortunetly don’t work for methods, only for instance variables.

There are two workarounds to implement protected and private methods.

1. Let the private methods be part of the implementation file only. For instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Car.h:
 
@interface Car {
    int   tires;
}
-(id) init;
@end
 
Car.m:
@implementation Car
 
-(id) init
{
    [super init];
    [self setupDefaultValues];
    return self;
}
 
// private function
-(void) setupDefaultValues
{
    ; // Custom code
}
 
@end
Car.h:

@interface Car {
    int   tires;
}
-(id) init;
@end

Car.m:
@implementation Car

-(id) init
{
    [super init];
    [self setupDefaultValues];
    return self;
}

// private function
-(void) setupDefaultValues
{
    ; // Custom code
}

@end

Using this approach your methods can be only private, which may occures problems in the future, when you try to overload a derived method, and you can not change its visibility to protected.

The compiler will throw a warning message for [self setupDefaultValues], because the compiler will be looking for this method in the @interface definition.

2. The second solution uses category pattern, which splits the header file into two parts. The main part contains the public, and the other includes the private part of your class.

In this example the Car.h is the same as in the first example, so I’ll just write the additional lines.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Car.h
----------------
 
@interface Car (PrivateMethods)
 
- (void) setupDefaultValues
 
@end
 
Car.m
----------------
@implementation Car (PrivateMethods)
 
- (void) setupDefaultValues
{
    ; // Custom code
}
 
@end
Car.h
----------------

@interface Car (PrivateMethods)

- (void) setupDefaultValues

@end

Car.m
----------------
@implementation Car (PrivateMethods)

- (void) setupDefaultValues
{
    ; // Custom code
}

@end

I haven’t found nice solution for protected methods yet. There is a convention to begin  protected methods with _ mark, but I like when the compiler warns me to somebody tries to call a protected method, and I’m not forced to dig up the code for checking prefixes.