Advertising Linux Services via Avahi/Bonjour

Update: most of this information is still correct but an update for combining service definitions into one file and setting an icon is available here: http://holyarmy.org/2008/11/bonjour-avahi-addendum

In my last post I outlined how I followed others’ directions to enable netatalk on Linux and Time Machine backups to a shared AFP folder. Originally, I also described how to put all your shares on netatalk. I suppose if only have Mac clients or you REALLY want to use AFP, you can do so. As I worked with files over AFP shares, I started noticing that the performance seemed to be quite bad. No, I didn’t benchmark, but copying large video files to a shared folder over my gigabit network was substantially slower over AFP (netatalk) than over CIFS/SMB (samba). I use my network shares pretty heavily, so this was a concern. Also, netatalk tries very hard to replicate an HFS filesystem complete with resource fork support. This means that your shared directories end up with lots of extra folders named “.AppleDouble”(and a few others) containing Mac specific info. (Note: even on CIFS you’ll get the “.AppleDB” folders unless you disable a setting in Finder. I can deal with .AppleDB better than .AppleDouble AND .AppleDB) So, because of these two issues I decided to try using CIFS and samba again.

My first experiment was to try sharing a “time_machine” folder via CIFS, and using the “defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1” hack on the previous post, I was able to get Time Machine to perform a backup. It worked, but in the end I decided that if I need to restore from this backup, I want my resource forks intact. To do that, I need AFP and netatalk. So, I removed all AFP shares except the one for Time Machine backup share. Now my Time Machine would backup and restore happily, and I could again use my Samba shares.

One of the cool things about having used AFP/netatalk was that my server and folders were showing up in my finder window. Well, that’s not a feature of AFP or netatalk, its actually avahi/Bonjour doing that. So, all I had to do was advertise the services. If you followed my previous posts, you’ve already created a service for AFP/netatalk on your server; it’s simple to create more, just add more service files. I’ll paste in all of my service files here:

/etc/avahi/services/aftp.service/

afpd.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h AFP</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
</service-group>

apache.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h HTTP</name>
<service>
<type>_http._tcp</type>
<port>80</port>
</service>
</service-group>

rfb.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h VNC</name>
<service>
<type>_rfb._tcp</type>
<port>5901</port>
</service>
</service-group>

samba.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_smb._tcp</type>
<port>139</port>
</service>
</service-group>

sftp.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h SFTP</name>
<service>
<type>_sftp-ssh._tcp</type>
<port>22</port>
</service>
</service-group>

ssh.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h SSH</name>
<service>
<type>_ssh._tcp</type>
<port>22</port>
</service>
</service-group>

So, you can see that I’m announcing Samba/CIFS file, AFP file, Apache HTTPd, VNC (RFB) Remote Desktop, SSH and SFTP services. Leopard’s Finder only displays the CIFS, AFP and RFB services, but other applications with Bonjour support will see the other services. By default Finder opens “Screen Sharing” when you use the advertised service, but Chicken of the VNC can also browse for Bonjour enabled VNC servers. Below are screen shots of my Finder showing the shared services.

finder_bonjour_vnc.jpg
finder_bonjour_cifs.jpg
finder_bonjour_cifs.jpg

No restarts are needed for anything at this point. The services should automatically be picked up by the Linux avahi daemon, but if you really need to, you may execute /etc/init.d/avahi-daemon restart .

17 thoughts on “Advertising Linux Services via Avahi/Bonjour

  1. Actual mac servers combine all the services into one service group with the same name. This lets the leopard finder combine like services into one icon. This is most apparent when you have afp, samba (avahi), and samba broadcasting its NetBIOS name. If you make them all one service group with the same name (same as the NetBIOS name ‘%h’) The Leopard finder will show only one icon and preferentially use afp over samba over finding samba via NetBIOS.

    Also you can specify your finder icon for a service group like so:
    http://www.simonwheatley.co.uk/2008/04/06/avahi-finder-icons/

Leave a Reply

Your email address will not be published. Required fields are marked *