Advertising Linux Services via Avahi/Bonjour
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.



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 .
Comments
Comment from Benjamin
Time: April 25, 2008, 4:35 pm
Good stuff, George. Thanks for the link!
Pingback from RayRay Is Forever » Blog Archive » Avoid OSX Metadata on Network Shares
Time: June 11, 2008, 12:19 am
[...] services that you want to appear in Finder, Terminal, and other places automagically, check out HolyArmy.org Posted in Personal Updates, Server Blog [...]
Pingback from Ubuntu als Mac | Bruis blog
Time: October 5, 2008, 5:09 am
[...] Advertise your services Laat Avahi je services over het netwerk verspreiden, bonjour zal het geweldig [...]
Comment from Farhad Khan
Time: October 26, 2008, 8:28 am
I tried the service descriptions above but for some reason I can never get ssh to show up as a sevice in dns-sd or Bonjour. HTTP worked fine. Do you know why?
Pingback from Benjamin Sherman » Bonjour Avahi Addendum
Time: November 6, 2008, 9:23 am
[...] while back I wrote about advertising Linux services via Avahi/Bonjour. Since then I’ve made a few changes to my [...]
Comment from benjamin
Time: November 6, 2008, 9:26 am
Farhad,
See my latest post for a better way to list services: http://holyarmy.org/benjamin/2008/11/bonjour-avahi-addendum/
But regarding SSH showing up, it doesn’t in Finder’s Bonjour view, but I was able to see it using the command-line program dns-sd in Terminal.
$ dns-sd -L myserver _ssh
Hope that helps!
Ref:
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/dns-sd.1.html
Comment from matt
Time: November 16, 2008, 10:23 pm
If you want gui, you can see all the linux advertised services from a Mac using Bonjour Browser
http://www.tildesoft.com
Pingback from Ubuntu and Mac OS X Integration - blog.scottlowe.org - The weblog of an IT pro specializing in virtualization, storage, and servers
Time: January 2, 2009, 8:36 am
[...] systems running Avahi or Macs. I’d installed Avahi earlier and used some service definitions from this article and this blog post to advertise Samba and HTTP. In addition, after installing Firefly, I’d [...]
Comment from George Brownlee
Time: April 25, 2008, 3:45 pm
Have a look at
http://www.simonwheatley.co.uk/2008/04/06/avahi-finder-icons/
He’s figured out how to specify the icons displayed in the finder pane, i.e. AirPort Express, eMac, iMac etc