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.
Stephen Sugden committed
May 1, 2015 at 11:20 UTC
9fc7dfbd15a943b0786e5f18af00f18bef6d2017
3 files changed
+31
-7
misc/launchd/README.md
+1
-5
@@ -1,9 +1,5 @@
1
# ipfs launchd agent
2
3
-A bare-bones launchd agent file for ipfs. To have launchd automatically run the ipfs daemon for you, do the following:
4
-
5
- mkdir -p ~/Library/LaunchAgents
6
- cp misc/launchctl/io.ipfs.ipfs-daemon.plist ~/Library/LaunchAgents/
7
- launchctl load ~/Library/LaunchAgents/io.ipfs.ipfs-daemon.plist
3
+A bare-bones launchd agent file for ipfs. To have launchd automatically run the ipfs daemon for you, run `./misc/launchd/install.sh`
4
5
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.
misc/launchd/install.sh
new
+23
@@ -0,0 +1,23 @@
1
+#!/bin/bash
2
+
3
+src_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
4
+plist=io.ipfs.ipfs-daemon.plist
5
+dest_dir="$HOME/Library/LaunchAgents"
6
+IPFS_PATH="${IPFS_PATH:-$HOME/.ipfs}"
7
+escaped_ipfs_path=$(echo $IPFS_PATH|sed 's/\//\\\//g')
8
+
9
+mkdir -p "$dest_dir"
10
+
11
+sed 's/{{IPFS_PATH}}/'"$escaped_ipfs_path"'/g' \
12
+ "$src_dir/$plist" \
13
+ > "$dest_dir/$plist"
14
+
15
+launchctl list | grep ipfs-daemon >/dev/null
16
+if [ $? ]; then
17
+ echo Unloading existing ipfs-daemon
18
+ launchctl unload "$dest_dir/$plist"
19
+fi
20
+
21
+echo Loading ipfs-daemon
22
+launchctl load "$dest_dir/$plist"
23
+launchctl list | grep ipfs-daemon
misc/launchd/io.ipfs.ipfs-daemon.plist
+7
-2
@@ -11,12 +11,17 @@
11
<string>ipfs</string>
12
<string>daemon</string>
13
</array>
14
+ <key>EnvironmentVariables</key>
15
+ <dict>
16
+ <key>IPFS_PATH</key>
17
+ <string>{{IPFS_PATH}}</string>
18
+ </dict>
19
<key>RunAtLoad</key>
20
<true/>
21
<key>StandardErrorPath</key>
17
- <string>/usr/local/var/log/ipfs.err</string>
22
+ <string>{{IPFS_PATH}}/logs/stderr.log</string>
23
<key>StandardOutPath</key>
19
- <string>/usr/local/var/log/ipfs.log</string>
24
+ <string>{{IPFS_PATH}}/logs/stdout.log</string>
25
</dict>
26
</plist>
27