Skip to content

Instantly share code, notes, and snippets.

@edrex
Last active January 6, 2017 14:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edrex/c929c6d3224654276446 to your computer and use it in GitHub Desktop.
Save edrex/c929c6d3224654276446 to your computer and use it in GitHub Desktop.
Automatically start Camlistore at login on OSX

I store my documents in a Camlistore, with a local instance running on my workstation and sync to an s3 bucket and a fixed server. Since I set this up 2 years ago, I've been manually starting camlistored and cammount inside a tmux session each time I log in to OSX.

Today I finally got around to setting up these processes to to start using the native OSX facility, launchd plists.

Steps:

  • camlistored and cammount should be in /usr/local/bin. I have them symlinked via

cd /usr/local/bin && ln -s ~/go/camlistore.org/bin/cam* . && cd - ```

  • Copy these plists to ~/Library/LaunchAgents. plists require absolute paths so replace each /Users/eric with your home dir.
    launchctl load ~/Library/LaunchAgents/camlistored.plist
    launchctl load ~/Library/LaunchAgents/cammount.plist
    

Details:

  • Robust to failures (keep alive)

  • Camlistored activates when cammount activates (but doesn't deactivate, after cammount deactivates, which seems like a bug in Launchd, if I understand the docs. To stop both, run:

    launchctl unload ~/Library/LaunchAgents/cammount.plist
    launchctl unload ~/Library/LaunchAgents/camlistored.plist
    
  • Service logs in ~/Library/Logs. You can view them in Console.app.

  • If you run a remote server, you could just use cammount.plist

  • If you want to edit these files, you might want to download the LaunchControl.app editor, which provides a number of niceties:

    • Inline docs for plist directives
    • Continuous validation
    • Auto reload on save
    • ...
<?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>
<dict>
<key>OtherJobActive</key>
<dict>
<key>cammount</key>
<true/>
</dict>
<key>OtherJobEnabled</key>
<dict>
<key>cammount</key>
<true/>
</dict>
</dict>
<key>Label</key>
<string>camlistored</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/camlistored</string>
<string>-openbrowser=false</string>
</array>
<key>StandardErrorPath</key>
<string>/Users/eric/Library/Logs/Camlistored.log</string>
<key>StandardOutPath</key>
<string>/Users/eric/Library/Logs/Camlistored.log</string>
</dict>
</plist>
<?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>Label</key>
<string>cammount</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/cammount</string>
<string>/Users/eric/Store</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/eric/Library/Logs/Cammount.log</string>
<key>StandardOutPath</key>
<string>/Users/eric/Library/Logs/Cammount.log</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment