├── readme.mdown └── install.sh /readme.mdown: -------------------------------------------------------------------------------- 1 | # Improvements to the Fitbit installer for Mac OS X 2 | 3 | Out of the box, the Fitbit software sends all its logs straight to Console. This is unnecessarily noisy if you use Console a lot, and it bloats the syslog archives. This little fix-up script for the Fitbit installer will: 4 | 5 | - Redirect fitbitd's logs to its own log file at /var/log/fitbitd.log 6 | - Add an entry to OS X's built-in log rotation to compress and turn over these logs when they get large. 7 | 8 | ## To Install 9 | 10 | Mimicking [Homebrew](http://brew.sh), the install process is simple: 11 | 12 | curl -fsSL https://raw.github.com/cbowns/fitbit/master/install.sh | zsh -s 13 | 14 | ## Having issues? 15 | 16 | File a bug at https://github.com/cbowns/fitbit/issues/new with as much information as you can provide, and I'll see what's up. -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | # A short script to clean up fitbitd's verbose logging, by redirecting it to a logfile. 3 | # Created by Christopher Bowns on 2011-09-25 4 | # Copyright 2011 Mechanical Pants Software 5 | 6 | # here's the lowdown: 7 | # 1. set /Library/LaunchDaemons/com.fitbit.fitbitd's StandardErrorPath to /var/log/fitbitd.log 8 | # 2. kick launchd so it sees the new entry 9 | # 3. install an entry in newsyslog.conf so we rotate and toss old logs periodically 10 | 11 | githubissues="https://github.com/cbowns/fitbit/issues/new" 12 | 13 | fitbitplistshort="/Library/LaunchDaemons/com.fitbit.fitbitd" 14 | fitbitplist="$fitbitplistshort.plist" 15 | stderrkey="StandardErrorPath" 16 | stdoutkey="StandardOutPath" 17 | fitbitlogpath_noprivate="/var/log/fitbitd.log" 18 | fitbitlogpath="/private$fitbitlogpath_noprivate" 19 | fitbitjobkey="com.fitbit.fitbitd" 20 | 21 | 22 | { defaults read $fitbitplistshort $stderrkey 2>&1 } > /dev/null 23 | stdErrExists=$? 24 | { defaults read $fitbitplistshort $stdoutkey 2>&1 } > /dev/null 25 | stdOutExists=$? 26 | if [ $stdErrExists != 0 -o $stdOutExists != 0 ]; then 27 | echo "Setting up fitbitd output redirection" 28 | 29 | sudo defaults write $fitbitplistshort $stderrkey "$fitbitlogpath" 2>&1 > /dev/null 30 | sudo defaults write $fitbitplistshort $stdoutkey "$fitbitlogpath" 2>&1 > /dev/null 31 | sudo chmod a+r $fitbitplist 32 | 33 | sudo touch $fitbitlogpath 34 | sudo chown nobody:admin $fitbitlogpath 35 | 36 | sudo launchctl unload $fitbitplist 37 | sudo launchctl load $fitbitplist 38 | 39 | sudo launchctl list $fitbitjobkey | grep $stderrkey 2>&1 > /dev/null 40 | stdErrRedirected=$? 41 | sudo launchctl list $fitbitjobkey | grep $stdoutkey 2>&1 > /dev/null 42 | stdOutRedirected=$? 43 | if [ $stdErrRedirected != 0 -o $stdOutRedirected != 0 ]; then 44 | echo "Couldn't confirm log redirection in launchd job! Please report an issue at $githubissues." 45 | exit 1 46 | else 47 | echo "fitbitd output redirection done" 48 | fi 49 | else 50 | echo "fitbitd's output is already redirected to $fitbitlogpath_noprivate, skipping launchd setup" 51 | fi 52 | 53 | 54 | newsyslogpath="/etc/newsyslog.conf" 55 | syslogRotationEntry="/var/log/fitbitd.log 666 5 5000 * J /var/run/com.fitbit.fitbitd.pid 14" 56 | 57 | grep $fitbitlogpath_noprivate $newsyslogpath 2>&1 > /dev/null 58 | exitStatus=$? 59 | if [ $exitStatus != 0 ]; then 60 | echo "Setting up fitbitd log rotation" 61 | # some trickery here with tee to append it as root but not print the output: 62 | echo $syslogRotationEntry | sudo tee -a $newsyslogpath 63 | else 64 | echo "Log rotation for $fitbitlogpath_noprivate is already installed to $newsyslogpath, skipping" 65 | fi 66 | --------------------------------------------------------------------------------