Start mysql as a daemon on OS X Mavericks on boot

I’ve been doing some work with WordPress and Joomla recently, which led to the need to have mysql up and running on my dev server; it’s a mac mini running OS X Mavericks Server.

I’d like the mysqld process to run as a daemon in the background after the server boots; that way I don’t have to log in and start the process after each server reboot.  I couldn’t find a recent, up-to-date faq for doing this, so I thought I would write what I did.

I’m a big fan of homebrew, so I used it to install mysql.

homebrew is a unix-style package manager for OS X; it’s awesome!

If you don’t have homebrew installed on your mac, you can get it by opening the terminal app and using this command:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Then to install mysql…

brew install mysql

Read the output of the above command carefully, as there are a few more steps that won’t be covered here today that are required to initialize and setup your new mysql database.

The homebrew mysql package comes with some info for automatically launching mysql on login. You can access the info with the following command:

brew info mysql

This is the last part of the output of the above command:

...
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start

Remember, I want to have mysql run as a daemon even when there is no user actively logged into the dev server…

This can easily be accomplished by copying the homebrew.mxcl.mysql.plist file that is provided with the homebrew mysql package to the /Library/LaunchDaemons/ folder and then making some edits to the file in it’s new location.

Here is the contents of the included plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.mysql</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/mysql/bin/mysqld_safe</string>
<string>--bind-address=127.0.0.1</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local/var</string>
</dict>
</plist>

There are a couple of issues that need to be addressed with the default plist file if you want to run mysql as a daemon.

  1. You’ll want to call the mysqld executable directly instead of invoking the mysqld_safe script.
  2. You need to provide the user account that you would like to have run the mysqld process.
  3. You need to provide the complete path to the WorkingDirectory; which on my system is /usr/local/var/mysql

Before getting started with any changes to the included plist file, make a copy in the /Library/LaunchDaemons/ folder:

sudo cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist /Library/LaunchDaemons/homebrew.mxcl.mysql.plist

Then open your favorite unix text editor (vim in my case):

sudo vim /Library/LaunchDaemons/homebrew.mxcl.mysql.plist

Then make the following edits…

To call mysqld directly edit the line:

<string>/usr/local/opt/mysql/bin/mysqld_safe</string>

and change it to:

<string>/usr/local/opt/mysql/bin/mysqld</string>

To add the user account that you would like to have run the mysqld process, add the following line under the <key>ProgramArguments</key> line:

<string>--user=mysqlusergoeshere</string>

where mysqlusergoeshere is the unix name of the account you want to run the mysql process.

After

<key>RunAtLoad</key>
<true/>

Add the following two lines:

<key>UserName</key>
<string>mysqlusergoeshere</string>

Make sure the path for your WorkingDirectory leads to folder where your mysql data is located; in my case this was /usr/local/var/mysql :

<key>WorkingDirectory</key>
<string>/usr/local/var/mysql</string>

Here is the contents of the complete plist file with all the necessary modifications:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.mysql</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/mysql/bin/mysqld</string>
<string>--bind-address=127.0.0.1</string>
<string>--user=mysqlusergoeshere</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>mysqlusergoeshere</string>
<key>WorkingDirectory</key>
<string>/usr/local/var/mysql</string>
</dict>
</plist>

Once you have all the changes made to the plist file, you’ll want to change ownership and permissions of the file so that it will work with the launchctl process.

If it isn’t already, change the owner to root and the group to wheel.

sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.mysql.plist

Set the appropriate permission by changing the file mode to 644:

sudo chmod 644 /Library/LaunchDaemons/homebrew.mxcl.mysql.plist

The last step is to load the plist with launchctl:

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.mysql.plist

mysqld should load immediately after this last command is run. It should also now load each time the system boots.

If you make changes to the plist file and need to reload it with launchctl, make sure you first unload the file:

sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.mysql.plist

I hope this guide helps anyone out who would like to have their homebrew mysql run as a daemon on OS X Mavericks.

Find My iPhone

find-my-iphone

Anyone who owns an Apple iPhone needs to install and configure this app!

When I first configured the Find My iPhone app, my initial thoughts were…this is sort of neat, but mostly a gimmick.

Ok, so it lets me see the current location of my iDevices (iPhones, iPads, etc…). Is it really going to help me locate a lost or stolen iPhone?

Well, the short answer is: YES!

Over the past several months I’ve used this app to successfully locate several misplaced iPhones.

A few weeks ago my wife couldn’t find her iPhone. We tried calling it, hoping to hear it ring, but after several tries…nothing. So I opened the find my iPhone app on my iPhone and voila, in about 15 seconds it told me that the phone was located in our driveway approximately where our minivan was sitting. The initial response was, “I’ve already looked in the minivan.” However, upon closer inspection, the missing iPhone was found under the center console.

The real test came this last week, as we flew home from a short family vacation in Missouri. Our flight had a connection through Newark, NJ, and just before landing at our final destination in Boston, my wife realized she did not have her iPhone. Unknowingly to us, it had fallen out of her purse on the first flight. To complicate matters it was on airplane mode, so the cell phone radio was off.

The first thing I did was open the Find My iPhone app on my iPhone and set the alert for her phone. I told the app to have her phone display a message as soon as it was found saying that it was lost and to call my iPhone’s number. I also told it to notify me via email as soon as her phone was located.

We reported the phone lost with the airline and went home. I checked the app a few times that evening and the phone could not be located.

Then at 11 PM that night, I received an email while sitting at my computer that said that her iPhone had been located. Before I could even launch the find my iPhone webpage, my phone rang. It was a cleaning lady on the plane in Indianapolis who had found the phone. She said as soon as she turned it on, it started making all sorts of noise and displaying the message that she needed to call me. She keep me on the phone as she walked to the Continental office to turn the phone in. While talking to her, I loaded the Find My iPhone webpage on my computer and watch as the phones location was updated every 30 secs or so.

Continental made arrangements to have the phone on a flight to Boston the next day, where I picked it up at the airport. Overall a resounding success for the Find My iPhone app!

To get the Find My iPhone app installed and working on your iPhone, iPad, or 4th gen iPod Touch there are a few things you need to do:

  1. Visit the App Store on your iPhone, iPad, or iPod Touch and download the Find My iPhone app.
  2. Use your Apple ID to sign in and register your device with the service.
  3. Use the same Apple ID to turn on the app on your other iDevices.

Now if one of your devices goes missing, you can use the app to attempt to locate it. For the location services to work, the device has to be turned on and connected to the internet either via Wifi or the cellular network. If it cannot be located, you can have it send you an email the next time it connects to the internet.

There are also options to lock the device or to remotely wipe the device. These options may be handy if you are having trouble recovering a lost or stolen device from it’s new owner.

Overall, I highly recommend this app based on personal experience. Download and configure it today!

Mac mini with Snow Leopard Server–Setup Tips

Macminisnowleopardserver

I recently decided to purchase an Apple Mac mini with Snow Leopard Server so that I could have a fully featured server providing services for my home network and some business interests.

The primary goals being:

  1. To eventually reduce the cost of maintaining calendar, email, and contact management services that push info to our mobile devices (iPhones, iPad, etc…). My goal here is to ditch mobile me.
  2. Establish a central file server to manage our growing collection of digital assets (photos, music, movies, documents, etc.).
  3. Facilitate server based Time Machine backups of all local mac computers on our home network.
  4. Manage user and computer accounts to control the level of service provided to the various household users.
  5. Establish a VPN to remotely access files and services on the home network.

A secondary goal being an overall refresh and improvement of my server management skills.

The features that attracted me to the Mac mini server were:

  • It’s small footprint
  • Extremely energy efficient design
  • Unlimited client license
  • Low cost
  • Ability to support and manage Mac, Windows, and linux clients.

The marketing info from Apple is very suggestive that a non IT person can easily setup and manage a Mac mini server. By using their included setup assistant, anyone familiar with Mac OS X is supposed to be able to quickly and easily have a fully functioning email, file, and directory server. I can confidently say that this is not the case. I have a substantial amount of experience with OS X, some OS X Server experience, and some linux admin experience. I thought I would give the setup assistant a try and see how easy it really can be to setup a Snow Leopard Server. Here is a brief summary of my results:

First try (setup assistant) = EPIC FAIL

Second try  (manual configuration) = SUCCESS

After reading a substantial amount of the server admin guides from Apple, and researching much info on the web, I now have a properly functioning Snow Leopard Server with the following services enabled:

  • DNS (Domain Name Server)
  • Open Directory
  • AFP (Apple Filing Protocol)
  • SMB (Windows file sharing)
  • NFS (Unix file sharing)

 I have migrated my user account from local accounts on the various macs, to a network account on the server. This was a challenging task to do correctly and there is virtually no documentation from Apple which provides an approach or framework to migrate local accounts to server accounts. A full write-up will be forthcoming…but in the mean time, a few things to consider:

  • Have a full admin account on your server that does not have the same long or short name as the account you plan on using as your everyday network account.
  •  Network accounts should have different long/short names than the local accounts on your Macs.
  • It is helpful to have a local admin account (backdoor account) for each mac in your network.
  • Back up all of your files on your local machines before you begin messing with the accounts!

 In the future, I plan on incrementally adding the following services to my server:

  • iCal Server
  • Address Book Server
  • VPN
  • Mail

The key to success was not allowing the setup assistant to configure any services. Just start with a minimal server install and configuration. Then, starting with the DNS service, incrementally added services by configuring them manually with the Server Admin application.

Setting up your DNS service is the most important step and requires forethought and planning to avoid having to reconfigure your server in the future; this is where I screwed up the first time (DNS config), and then the server assistant took it from there and hosed the rest of the services. I tried to repair manually using Server Admin and at the command line, but in the end, it was just easier to start over.

I think if I had a more complete understanding of DNS during the first attempt with the setup assistant, it is very likely that I would have been successful configuring my server. So I don’t think that there is any problem with Apple’s setup assistant per se, it’s just that the setup assistant assumes that you have at least a baseline knowledge of DNS service settings. It is very easy to quickly get of course with the setup assistant despite the fact that it was designed to make server setup a breeze.

When setting up DNS service on your server, keep these things in mind:

  • Make sure you understand what constitutes a fully qualified domain name (FQDN).
  • Example: myserver.mydomain.com
  • Do not use .local or .private in your FQDN.
  • Register a unique domain name for your server, even if you intend on having a private network behind a firewall.
  • Use Google’s DNS servers, 8.8.8.8 and 8.8.4.4, as your “Forwarder IP addresses.” You will get fast and accurate domain name resolution without ending up at your ISP’s search page when they can’t resolve the domain your looking for.
  • Double check your DNS server and ensure that it is working before moving on to setting up other services.

In the near future, I plan on writing a comprehensive online guide to setting up a functioning Snow Leopard Server that the average Mac OS X user can follow and have a higher likelihood of success than relying on the setup assistant alone. Update (3/12/2011): Since writing this post I have discovered several very good online resources for Snow Leopard Server setup and configuration. So rather than re-invent the wheel, I am just going to post some links to these excellent resources:

wazmacdotcom OSX 10.6 Server setup

DNS Tips: Establishing a DNS Server on Snow Leopard | Hoffmanlabs

Bringing up a Mac mini Server

I do think that OS X Server is easier to setup and manage than say a Windows 2003 server or a linux server. However, it is definitely not as easy as Apple makes it sound on their Mac mini Server webpage.

Don’t let that discourage you from taking the leap!

  • If you’re growing a small business around the mac platform (or Windows),
  • and you’d like to provide email, calendar, and address book services while keeping overall IT costs low.
  • Or you have a large technology investment at home (multiple Macs/iPhones/iPads, multiple users, and lots of files), need centrally managed file storage, and would like to provide your own services. 

Then you can definitely benefit from leveraging a Mac OS X unlimited client license server to meet your evolving needs.

Also, setting up and running your own Snow Leopard Server = MAXIMUM COOLNESS FACTOR!

 

Setting Up A Charging Station

One of the quickest paths to BDH (bad digital hygiene), is not charging your devices. Devices are useless if they don’t have an adequate charge.

If you have multiple devices that need to be charged each day, I recommend setting up a charging station.

In it’s simplest form, a charging station can be nothing more than a power strip with your device’s chargers attached, located in a convenient place.

No one likes the clutter associated with a bunch of loose power cords. So often it is desirable to find a way to disguise your charging station. One option is to hide your charging station in a closet or on a shelf. Here’s an example on the top of a cabinet (the powerstrip is behind the cabinet out of view).

Charging Station On Cabinet

Use inexpensive cable ties to organize and band together all of the loose cables for a neat and tidy look.

Cable Ties

Alternatively, you can also buy a dedicated charging station (a.k.a. charging valet) like the one pictured below. These usually have an opening on the back for a small power strip that you can plug your power cords into. The cords then feed through the charging station to a few holders for your devices so that you can neatly charge them without all of the clutter. An added bonus is that most also have a few drawers that can be used to store other personal items or accessories for your devices. Dedicated charging stations have become very popular and now you can find many different styles and manufacturers. Search online for the most variety.

Charging Station

Recently, I’ve noticed these wireless charging mats at Best Buy.

PowerMat

They are supposed to be the one solution to all of your charging needs. However, if you jump on Amazon.com, you’ll find mostly negative to luke-warm reviews of these types of products (Duracell makes one too). The most consistent complaints being the lack of device compatibility and the bulky sleeves which enable the wireless charging feature. I haven’t tested any, but my recommendation at this point is to stay away from them.

If you’re a road warrior who commutes to work each day, or if you’re on the road a lot for your job, you can also setup a charging station in your car via the 12 volt cigarette lighter or dedicated power port. Some newer vehicles, including many minivans ans SUVs, also come with optional factory installed power inverters which you can plug your power cord into directly without the need to buy a new 12 volt vehicle charging cord.

As with all digital hygiene, the most important consideration is to find something that works for you consistently. Try not to get too complicated, remember the adage keep it super simple (k.i.s.s.). If the recommendations above seem like too much effort, just find a consistent place to plug in your device everyday and you’ll be fine.

Establishing Your Digital Hygiene Routine

This has to be one of the most important aspects of maintaining good digital hygiene. Without a regular routine, you're very likely to skip an important hygiene task and end up hosed. Let's face it, most of us are creatures of habit. We tend to stick to our routines and the resulting familiarity is a balancing force in our busy lives. Don't follow your routine and what happens? You may forget something.

Your digital hygiene has to be approached in the same way. You need to build it into your daily routine. Just like you brush your teeth every night before bed, you need to plug your cell phone in every night before bed. I bet most of you already have some sort of loose routine that you follow. I'm just suggesting that you'll be more consistent if you give your routine a little thought and consider all the aspects of you digital life that may require regular, hygiene. There may be many aspects of your digital life that you are neglecting.

I won't even try to tell you how to setup your routine. Everyone is different and the routine that works for me may not work for you. I can suggest some things that you will want to consider building into your routine.

1. Charge your devices! Plug your cell phone in at the same time and place every day. I cannot stress how important this is. Leave it laying on the kitchen table, and you're likely to find it there the following morning with a dead battery.

2. Ditto for any other digital devices that you depend on every day such as digital cameras, iPods, iPads, PDAs, or laptops.

3. If you're a regular email user, check your email at least once a day. Find a consistent time that works for you and do it every day. I can write a whole post on all of the advantages that come with keeping up with your email inbox. Or, you can ask my wife how frustrated she gets when she hasn't checked her email for a week or so…I love you sweetie 😉

4. Back up your important digital files at least once a month. For some folks who are heavy users of technology, you may want to do this at least twice a month. Pick a date that you will remember such as the 1st, 15th, or every payday. This means: sync your iPod/iPad, back-up your Blackberry, archive your contacts, back-up your iTunes library, burn a CD or DVD copy of your digital photos, etc…

5. Update your antivirus software and database at least once a month. Most antivirus software have features to do this automatically at some set interval. However, most people don't leave their computers on all the time, so these regular updates are often bypassed. Use the strategy above to pick a date each month to update your antivirus software and database. The more frequently the better!

6. Check for updates of your operating system at least once a month. On a Windows machine, this is the Windows Update. On a Mac, this is Software Update. Just like antivirus software, most operating systems have a schedule to check for automatic updates at some defined interval. Many folks either don't leave their computer on or elect to by-pass the updates when prompted by the operating system. Use the same strategy as above and pick a date each month to run your operating system's update software. Updates are vital for keeping your system healthy and vulnerability free.

Of course, this short list is not all inclusive. If you have other data or devices that you use regularly, or are important, you'll need to work them into your routine too.

What if I've tried a routine and it's not working?

Don't give up!

Try again!

Adjust your routine, mix it up!

Change the times for certain tasks.

Set yourself reminders, either high tech or low tech. Use your smartphone or PDA to set a reminder on your calendar. This is especially helpful for those hygiene tasks that are only done once a month. Put a sticky on the mirror in the bathroom that says, charge cell phone. Anything that will help you remember for the first few days, weeks, or months.

With a little persistence, you'll soon find that you don't need most of the reminders anymore.

Above all, the most important thing is to be consistent.

Give it a try and let me know how it works!

www.digitalhygiene.com goes live!

Welcome to the official launch of digitalhygiene.com!

Your #1 source on the web for smart advice to manage your digital life!

Over the next few weeks, I'll be adding a tremendous amount of content as I get the blog up and running. My goal with this site is to provide informative, useful, and easy to understand tips, articles, and reviews which will help the average person keep their digital life healthy. Tech savvy readers should also find the content informative and useful.

I hope you enjoy digitalhygiene.com and I welcome feedback and suggestions. Both to make the site better and also to address topics that are of interest my readers. So please take a few moments to leave some comments.