From 904ce1080e0ba14754d5ed05befb7ae8f2f56a84 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Thu, 30 Apr 2015 16:54:06 +0200 Subject: [PATCH 1/2] Add launchctl agent plist for OSX I found this useful to have, and figured it might save somebody else a few minutes of re-inventing the wheel. --- misc/launchd/README.md | 9 +++++++++ misc/launchd/io.ipfs.ipfs-daemon.plist | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 misc/launchd/README.md create mode 100644 misc/launchd/io.ipfs.ipfs-daemon.plist diff --git a/misc/launchd/README.md b/misc/launchd/README.md new file mode 100644 index 000000000..ab0ed2fc5 --- /dev/null +++ b/misc/launchd/README.md @@ -0,0 +1,9 @@ +# ipfs launchd agent + +A bare-bones launchd agent file for ipfs. To have launchd automatically run the ipfs daemon for you, do the following: + + mkdir -p ~/Library/LaunchAgents + cp misc/launchctl/io.ipfs.ipfs-daemon.plist ~/Library/LaunchAgents/ + launchctl load ~/Library/LaunchAgents/io.ipfs.ipfs-daemon.plist + +Note that the `ipfs` binary must be on the *system* PATH for this to work. Adding a symlink in /usr/bin works well enough for me. diff --git a/misc/launchd/io.ipfs.ipfs-daemon.plist b/misc/launchd/io.ipfs.ipfs-daemon.plist new file mode 100644 index 000000000..2012623a6 --- /dev/null +++ b/misc/launchd/io.ipfs.ipfs-daemon.plist @@ -0,0 +1,22 @@ + + + + + KeepAlive + + Label + io.ipfs.ipfs-daemon + ProgramArguments + + ipfs + daemon + + RunAtLoad + + StandardErrorPath + /usr/local/var/log/ipfs.err + StandardOutPath + /usr/local/var/log/ipfs.log + + + From 9fc7dfbd15a943b0786e5f18af00f18bef6d2017 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Fri, 1 May 2015 11:20:30 +0200 Subject: [PATCH 2/2] Template plist to work around launchd limitations `launchd` doesn't allow you to *use* environment variables. Nor does it support tilde-expansion of program names & arguments after OSX 10.10. To work around this, I've made the plist file a template and included a small install script that will interpolate the correct values. --- misc/launchd/README.md | 6 +----- misc/launchd/install.sh | 23 +++++++++++++++++++++++ misc/launchd/io.ipfs.ipfs-daemon.plist | 9 +++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100755 misc/launchd/install.sh diff --git a/misc/launchd/README.md b/misc/launchd/README.md index ab0ed2fc5..cd4d6207e 100644 --- a/misc/launchd/README.md +++ b/misc/launchd/README.md @@ -1,9 +1,5 @@ # ipfs launchd agent -A bare-bones launchd agent file for ipfs. To have launchd automatically run the ipfs daemon for you, do the following: - - mkdir -p ~/Library/LaunchAgents - cp misc/launchctl/io.ipfs.ipfs-daemon.plist ~/Library/LaunchAgents/ - launchctl load ~/Library/LaunchAgents/io.ipfs.ipfs-daemon.plist +A bare-bones launchd agent file for ipfs. To have launchd automatically run the ipfs daemon for you, run `./misc/launchd/install.sh` Note that the `ipfs` binary must be on the *system* PATH for this to work. Adding a symlink in /usr/bin works well enough for me. diff --git a/misc/launchd/install.sh b/misc/launchd/install.sh new file mode 100755 index 000000000..3d18e8526 --- /dev/null +++ b/misc/launchd/install.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +src_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +plist=io.ipfs.ipfs-daemon.plist +dest_dir="$HOME/Library/LaunchAgents" +IPFS_PATH="${IPFS_PATH:-$HOME/.ipfs}" +escaped_ipfs_path=$(echo $IPFS_PATH|sed 's/\//\\\//g') + +mkdir -p "$dest_dir" + +sed 's/{{IPFS_PATH}}/'"$escaped_ipfs_path"'/g' \ + "$src_dir/$plist" \ + > "$dest_dir/$plist" + +launchctl list | grep ipfs-daemon >/dev/null +if [ $? ]; then + echo Unloading existing ipfs-daemon + launchctl unload "$dest_dir/$plist" +fi + +echo Loading ipfs-daemon +launchctl load "$dest_dir/$plist" +launchctl list | grep ipfs-daemon diff --git a/misc/launchd/io.ipfs.ipfs-daemon.plist b/misc/launchd/io.ipfs.ipfs-daemon.plist index 2012623a6..e7bf9a6e3 100644 --- a/misc/launchd/io.ipfs.ipfs-daemon.plist +++ b/misc/launchd/io.ipfs.ipfs-daemon.plist @@ -11,12 +11,17 @@ ipfs daemon + EnvironmentVariables + + IPFS_PATH + {{IPFS_PATH}} + RunAtLoad StandardErrorPath - /usr/local/var/log/ipfs.err + {{IPFS_PATH}}/logs/stderr.log StandardOutPath - /usr/local/var/log/ipfs.log + {{IPFS_PATH}}/logs/stdout.log