Posts tagged command line

All posts

Stop MySQL being loaded on OS X boot

Right now I find myself working on a porject that uses MongoDB, and sometimes I work on projects with PostgreSQL and other times on projects that use MySQL. The difference is that I have to manually load both MongoDB (mongod) and PostgreSQL (I use the Heroku app) when I want to use them, but MySQL is loaded in my system by default.

Thinking on an all-or-none solution, I decided to convert MySQL in a service run on demand, instead of a resident one. I have installed MariaDB via Homebrew, so:

  ➜  julitrows.gitlab.com git:(master) ✗ brew info mariadb
  mariadb: stable 5.5.34, devel 10.0.7
  http://mariadb.org/
  ...
  **BLAH BLAH BLAH **
  ...
  To load mariadb after an update
      launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
      launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

So the second to last line is what we are looking for. By running:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

We’ll remove mysql from being run at startup.

And when we want to use mysql, just do mysql.server start, and mysql.server stop

Easy!


Clean unneeded dependencies on Homebrew

Let’s say you’ve uninstalled a formula with Hombrebrew that it’s no longer needed. Homebrew won’t clean the associated dependencies that are no longer needed. You can do this by running:

$ brew rm $(join <(brew leaves) <(brew deps <FORMULA>))

This calls for the formula dependencies and does a join with the installed packages that are not dependencies of other packages, and uninstall the resulting list of packages.

CAVEAT EMPTOR: This method uninstalled Qt from my computer, and I needed it for Capybara. This happened because brew only takes into account dependencies of programs installed with brew. Any dependency from outside brew is ignored.


Don't let roamers steal your trash

This one is for the IT boys in the dark basements. Love y’all :)

The problem

The results when using df and the sum of du are not the same. Example:

'Hey! I'm getting a 100% disk usage from df but I know I have free space, I've just rm-ed 10GB worth of files.'

The (probable) cause

The df results sync with the actual usage of hd space from time to time. Also, you might have processes that have that file still opened for some reason, even if it’s deleted. Most probably those processes are dead, undead, zombies, infected or whatever you might want to call them. I’ll call them ‘roamers’.

When the computer is rebooted, the roamers are killed along with any other process in the system, and the deleted files are finally purged, but let’s say you can’t afford to reboot the machine, i. e.: you’re working on a server.

What would Grimes do?

Use this command:

lsof +L1

It lists the opened files, and the +L1 filter will leave only those which are being used by just 0 or 1 processes. You might also want to add some grep magic to be sure that you are working only with files that are marked for deletion.

$lsof +L1 | grep "deleted"

COMMAND PID  USER    FD  TYPE DEVICE SIZE/OFF NLINK NODE     NAME
roamer   38  rgrimes txt  REG  14,2    51288     0 58754819 /blah/meh (deleted)``

On the left you get the process name and pid, so the only thing left to do is to go all kill -9 on it’s arse. Be careful though, and kill processes only when you’re sure you won’t break anything else or you don’t have any other exits available.