- Sux Services on FreeBSD HOWTO -

Sux Services now run on FreeBSD 4.7, but, due to the nature of the native implementation of POSIX threads under FreeBSD, you must install some additional packages to make Sux Services run.

Prerequisites


Port Notes
LinuxThreads

This is the LinuxThreads FreeBSD port. Native FreeBSD threads are user-level threads, whilst native Linux Threads are kernel-level threads. Because Sux Services main development is done on Linux, and because FreeBSD 5 has more and more support for kernel threads, I decided to use LinuxThreads to port the Services on FreeBSD.
For a comprehensive discussion about kernel- and user-level threads follow this link.

LinuxThreads installation is pretty straightforward:



 root@twisted:~# cd /usr/ports/devel/linuxthreads
 root@twisted:/usr/ports/devel/linuxthreads# make install -DWITH_CONDWAIT_PATCH
  < ... compilation process ... >
 root@twisted:/usr/ports/devel/linuxthreads#
    

Now, you should have the linuxthreads libraries in /usr/local:



 root@twisted:/usr/ports/devel/linuxthreads# l /usr/local/lib/libl{gcc,thread}*
  152 -r--r--r--  1 root  wheel  - 140738 Mar 14 12:41 /usr/local/lib/liblgcc_r.a
  936 -r--r--r--  1 root  wheel  - 944736 Mar 14 12:41 /usr/local/lib/liblthread.a
    0 lrwxr-xr-x  1 root  wheel  -     15 Mar 14 12:41 /usr/local/lib/liblthread.so@ -> liblthread.so.2
  120 -r--r--r--  1 root  wheel  - 113496 Mar 14 12:41 /usr/local/lib/liblthread.so.2
    

Congratulations, LinuxThreads installation is complete :).

GLib 2.2
or later

GLib, "some useful routines of C programming", is a really nifty library. It is not a graphics library, instead it provides lots of data structures and subsystems that make the developer focus on writing good code, and not re-inventing the wheel everytime. Last but not least, it is thread-safe and offers an abstraction layer over the multiple threads implementations, making the code portable.

By default, the FreeBSD GLib port uses the native FreeBSD user-level threads. But, because the LinuxThreads implementation is as POSIX-Compliant as the native one, we can link GLib versus the LinuxThreads library.
In order to accomplish to this, we must compile the GLib port with some extra options:



 root@twisted:/usr/ports/devel/glib20# export LOCALBASE="/usr/local"
 root@twisted:/usr/ports/devel/glib20# LDFLAGS="-L${LOCALBASE}/lib -lintl -llthread -llgcc_r" \
 >CFLAGS="-I${LOCALBASE}/include -D_THREAD_SAFE -I${LOCALBASE}/include/pthread/linuxthreads" \
 >CPPFLAGS="-I${LOCALBASE}/include -D_THREAD_SAFE -I${LOCALBASE}/include/pthread/linuxthreads" \
 >make install
  < ... compilation process ... >
 root@twisted:/usr/ports/devel/glib20#
    

At this point, you should verify that libglib-2.0.so and libgthread-2.0.so dynamically links with liblthread.so:


    
 root@twisted:/usr/ports/devel/glib20# ldd /usr/local/lib/libglib-2.0.so
 /usr/local/lib/libglib-2.0.so:
         libintl.so.4 => /usr/local/lib/libintl.so.4 (0x2817d000)
         liblthread.so.2 => /usr/local/lib/liblthread.so.2 (0x28185000)
         libiconv.so.3 => /usr/local/lib/libiconv.so.3 (0x281a6000)
 root@twisted:/usr/ports/devel/glib20# ldd /usr/local/lib/libgthread-2.0.so
 /usr/local/lib/libgthread-2.0.so:
         libintl.so.4 => /usr/local/lib/libintl.so.4 (0x2810a000)
         liblthread.so.2 => /usr/local/lib/liblthread.so.2 (0x28112000)
         libglib-2.0.so.200 => /export/bsdprt/devel/glib20/work/glib-2.2.1/glib/.libs/libglib-2.0.so.200 (0x28133000)
         libiconv.so.3 => /usr/local/lib/libiconv.so.3 (0x281ab000)
 root@twisted:/usr/ports/devel/glib20# 
    
If this is not your case, you surely missed something. If you did all the procedure and you are still having problems, drop me a note.

MySQL
threaded

client library

The threaded MySQL client library (libmysqlclient_r) is a C interface with a MySQL that gives the Services the ability to fetch data from a MySQL server.
Because we built GLib with linuxthreads, it`s good practice to build the client library with linuxthreads, too.
In order to accomplish this, you must pass some options to "make" when building.



 root@twisted:/usr/ports/databases/mysql323-client# make install -DWITH_LINUXTHREADS -DTHREAD_SAFE_CLIENT
  < ... compilation process ... >
 root@twisted:/usr/ports/databases/mysql323-client#
    

Now, you should have all the libraries installed in /usr/local:



 root@twisted:/usr/ports/databases/mysql323-client# l /usr/local/lib/mysql/libmysqlclient_r*
 200 -rw-r--r--  1 root  wheel  - 194884 Mar 14 12:52 /usr/local/lib/mysql/libmysqlclient_r.a
   1 -rwxr-xr-x  1 root  wheel  -    842 Mar 14 12:52 /usr/local/lib/mysql/libmysqlclient_r.la*
   0 lrwxr-xr-x  1 root  wheel  -     22 Mar 14 12:52 /usr/local/lib/mysql/libmysqlclient_r.so@ -> libmysqlclient_r.so.10
 152 -rwxr-xr-x  1 root  wheel  - 140170 Mar 14 12:52 /usr/local/lib/mysql/libmysqlclient_r.so.10*
 root@twisted:/usr/ports/databases/mysql323-client# 
    

And, like you did before, you should verify that libmysqlclient_r dynamically links with the LinuxThreads library:


    
 root@twisted:/usr/ports/databases/mysql323-client# ldd /usr/local/lib/mysql/libmysqlclient_r.so.10 
 /usr/local/lib/mysql/libmysqlclient_r.so.10:
        liblthread.so.2 => /usr/local/lib/liblthread.so.2 (0x28122000)
        libz.so.2 => /usr/lib/libz.so.2 (0x28143000)
        libcrypt.so.2 => /usr/lib/libcrypt.so.2 (0x28151000)
        libm.so.2 => /usr/lib/libm.so.2 (0x2816a000)
        libc.so.4 => /usr/lib/libc.so.4 (0x28069000)
    

Now, it`s time to install mysql server !

MySQL Server

The MySQL server is the database server that will hold Sux Services data.
Please note: mysql-server package installation on FreeBSD is always required, even if you run the database server on another host. Why ? Because the mysql_config script ships with the -server package, and is required by the ./configure script of Sux Services. IMHO, this script should be provided in the -client package, but I`m not a FreeBSD packager :).

The -server package installation is pretty equivalent to the -client one:



 root@twisted:/usr/ports/databases/mysql323-server# make install -DWITH_LINUXTHREADS -DTHREAD_SAFE_CLIENT
  < ... compilation process ... >
 root@twisted:/usr/ports/databases/mysql323-server#
    

After that, you should have the mysql_config script in /usr/local/bin:


    
 root@twisted:/usr/ports/databases/mysql323-client# l /usr/local/bin/mysql_config
 4 -r-xr-xr-x  1 root  wheel  - 3101 Mar 14 13:12 /usr/local/bin/mysql_config*
 root@twisted:/usr/ports/databases/mysql323-client# 
    

Please refer to the INSTALL.html file for information on how to insert the SQL database schemas and help files into your MySQL server.

libgnugetopt

libgnugetopt provides the getopt_long() function, used in Sux Services for command line arguments parsing.
Its installation requires nor special parameters neither particular effort:


    
 root@twisted:/usr/ports/devel/libgnugetopt# make install
  < ... compilation process ... >
 root@twisted:/usr/ports/devel/libgnugetopt#
    

   

Compilation process


The hard part is finished :). Now, you just need to compile the Services and run them :).
Only two parameters need to be passed to the ./configure script:

  • --with-linuxthreads=/usr/local tells the script that the linuxthreads port needs to be used, and it will find headers in /usr/local/include and libraries in /usr/local/lib.
  • --with-gnugetopt=/usr/local tells the script that the gnugetopt library needs to be used for getopt_long(), and it will find headers in /usr/local/include and libraries in /usr/local/lib.
    
    
     -[vjt@twisted:~/c/IRC/suxserv]-$ ./configure --with-linuxthreads=/usr/local --with-gnugetopt=/usr/local
      < ... configuration process ... >
     -[vjt@twisted:~/c/IRC/suxserv]-$ make
      < ... compilation process ... >
     -[vjt@twisted:~/c/IRC/suxserv]-$
     

    Congratulations ! You have just built Sux Services on FreeBSD :).
    For more information on how to run ( and, why not, debug ;) them, refer to the INSTALL.html file.

    Enjoy !


    --
    Marcello Barnaba (vjt@openssl.it)

    EOF