Tuesday, January 31, 2012

Netatalk - allowing Apples to share your Server oranges

Followed this tutorial here in order to be able to allow the MBP running Snow Leopard (and TimeMachine) to access the home server (custom build) and use for backups.

However, OSX would not allow access unless I restarted the service in Ubuntu using the following command in the terminal:
sudo /etc/init.d/netatalk restart
Google search revealed that many could not resolve this, and the few solutions I did find such as defining a static IP in Ubuntu did not work. The issue is, if the server was rebooted for whatever reason, I had to remember to ssh into it and run this command before I could access anything using the MBP.

What I wanted was a neat way to do this automatically after login, in case the server is rebooted. Easiest way is using the StartUp Applications menu. Ideally we'll give it a delay of say 30s to allow the netatalk daemon to start, before it is then restarted. Add an item, I call it "AFP restart" and enter the following as is into the command box (we use "bash -c" to define a string to be run)
bash -c "sleep 30s; sudo /etc/init.d/netatalk restart"
Save the command BUT before we restart to test, we have a problem with sudo and the terminal requiring a password. We can use visudo to remove this and allow it to run flawlessly in the background, which governs the sudoers file and defines permissions for sudo root commands.

In the terminal, enter it by typing "sudo visudo". At the bottom of the file, enter the following:
ALL = NOPASSWD: /etc/init.d/netatalk
This will now allow Startup Applications to perform the netatalk restart command without requiring the password prompt.

Write out the file (Ctrl+O) to save and then exit (Ctrl+X).

Restart the computer, and wait 45sec or so after you see the Server appear in the finder bar and voila, it should resolve the previous communication issue.