master
md 131 lines 3.96 KB
Rendered Raw
1 ## init system integration
2
3 go-ipfs can be started by your operating system's native init system.
4
5 - [systemd](#systemd)
6 - [LSB init script](#initd)
7 - [Upstart/startup job](#upstart)
8 - [launchd](#launchd)
9
10 ### systemd
11
12 For `systemd`, the best approach is to run the daemon in a user session. Here is a sample service file:
13
14 ```systemd
15 [Unit]
16 Description=IPFS daemon
17
18 [Service]
19 # Environment="IPFS_PATH=/data/ipfs" # optional path to ipfs init directory if not default ($HOME/.ipfs)
20 ExecStart=/usr/local/bin/ipfs daemon
21 Restart=on-failure
22
23 [Install]
24 WantedBy=default.target
25 ```
26
27 To run this in your user session, save it as `~/.config/systemd/user/ipfs.service` (creating directories as necessary). Once you run `ipfs init` to create your IPFS settings, you can control the daemon using the following commands:
28
29 * `systemctl --user start ipfs` - start the daemon
30 * `systemctl --user stop ipfs` - stop the daemon
31 * `systemctl --user status ipfs` - get status of the daemon
32 * `systemctl --user enable ipfs` - enable starting the daemon at boot
33 * `systemctl --user disable ipfs` - disable starting the daemon at boot
34
35 *Note:* If you want this `--user` service to run at system boot, you must [`enable-linger`](http://www.freedesktop.org/software/systemd/man/loginctl.html) on the account that runs the service:
36
37 ```
38 # loginctl enable-linger [user]
39 ```
40 Read more about `--user` services here: [wiki.archlinux.org:Systemd ](https://wiki.archlinux.org/index.php/Systemd/User#Automatic_start-up_of_systemd_user_instances)
41
42 #### P2P tunnel services
43
44 For running `ipfs p2p listen` or `ipfs p2p forward` as systemd services,
45 see [docs/p2p-tunnels.md](../docs/p2p-tunnels.md) for examples using the
46 `--foreground` flag and path-based activation.
47
48 ### initd
49
50 - Here is a full-featured sample service file: https://github.com/dylanPowers/ipfs-linux-service/blob/master/init.d/ipfs
51 - Use `service` or your distribution's equivalent to control the service.
52
53 ## upstart
54
55 - And below is a very basic sample upstart job. **Note the username jbenet**.
56
57 ```
58 cat /etc/init/ipfs.conf
59 ```
60 ```
61 description "ipfs: interplanetary filesystem"
62
63 start on (local-filesystems and net-device-up IFACE!=lo)
64 stop on runlevel [!2345]
65
66 limit nofile 524288 1048576
67 limit nproc 524288 1048576
68 setuid jbenet
69 chdir /home/jbenet
70 respawn
71 exec ipfs daemon
72 ```
73
74 Another version is available here:
75
76 ```sh
77 ipfs cat /ipfs/QmbYCwVeA23vz6mzAiVQhJNa2JSiRH4ebef1v2e5EkDEZS/ipfs.conf >/etc/init/ipfs.conf
78 ```
79
80 For both, edit to replace occurrences of `jbenet` with whatever user you want it to run as:
81
82 ```sh
83 sed -i s/jbenet/<chosen-username>/ /etc/init/ipfs.conf
84 ```
85
86 Once you run `ipfs init` to create your IPFS settings, you can control the daemon using the `init.d` commands:
87
88 ```sh
89 sudo service ipfs start
90 sudo service ipfs stop
91 sudo service ipfs restart
92 ...
93 ```
94
95 ## launchd
96
97 Similar to `systemd`, on macOS you can run `go-ipfs` via a user LaunchAgent.
98
99 - Create `~/Library/LaunchAgents/io.ipfs.go-ipfs.plist`:
100
101 ```xml
102 <?xml version="1.0" encoding="UTF-8"?>
103 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
104 <plist version="1.0">
105 <dict>
106 <key>KeepAlive</key>
107 <true/>
108 <key>Label</key>
109 <string>io.ipfs.go-ipfs</string>
110 <key>ProcessType</key>
111 <string>Background</string>
112 <key>ProgramArguments</key>
113 <array>
114 <string>/bin/sh</string>
115 <string>-c</string>
116 <string>~/go/bin/ipfs daemon</string>
117 </array>
118 <key>RunAtLoad</key>
119 <true/>
120 </dict>
121 </plist>
122 ```
123 The reason for running `ipfs` under a shell is to avoid needing to hard-code the user's home directory in the job.
124
125 - To start the job, run `launchctl load ~/Library/LaunchAgents/io.ipfs.go-ipfs.plist`
126
127 Notes:
128
129 - To check that the job is running, run `launchctl list | grep ipfs`.
130 - IPFS should now start whenever you log in (and exit when you log out).
131 - [LaunchControl](http://www.soma-zone.com/LaunchControl/) is a GUI tool which simplifies management of LaunchAgents.