Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd support #1430

Closed
notslang opened this issue Jun 29, 2015 · 14 comments · Fixed by #1447
Closed

systemd support #1430

notslang opened this issue Jun 29, 2015 · 14 comments · Fixed by #1447

Comments

@notslang
Copy link
Contributor

systemctl <command> ipfs doesn't work, which makes this a pain to manage as a daemon

@jbenet
Copy link
Member

jbenet commented Jun 29, 2015

@maxcrees
Copy link

maxcrees commented Jul 3, 2015

Here's a rudimentary systemd service file that I use:

[Unit]
Description=IPFS daemon
After=network.target

[Service]
ExecStart=/usr/bin/ipfs daemon

[Install]
WantedBy=multiuser.target

Place this in ~/.config/systemd/user/ipfs.service (create the directories as necessary) and start with systemctl --user start ipfs. This assumes the user already ran ipfs init.

@jbenet
Copy link
Member

jbenet commented Jul 3, 2015

@sroracle

it would be amazing to have an "example" in http://ipfs.io/docs/examples (https://github.com/ipfs/examples) that goes over systemd, initd, and other services.

(also, nice NERV avatar :) )

@jbenet
Copy link
Member

jbenet commented Jul 3, 2015

@sroracle

also, maybe:

Place this in ~/.config/systemd/user/ipfs.service (create the directories as necessary) and start with systemctl --user start ipfs. This assumes the user already ran ipfs init.

this could be a sh script

notslang added a commit to notslang/go-ipfs that referenced this issue Jul 6, 2015
notslang added a commit to notslang/go-ipfs that referenced this issue Jul 6, 2015
License: MIT
Signed-off-by: Sean Lang <slang800@gmail.com>
kbala444 pushed a commit to kbala444/go-ipfs that referenced this issue Jul 6, 2015
License: MIT
Signed-off-by: Sean Lang <slang800@gmail.com>
@sneak
Copy link

sneak commented Oct 10, 2018

The examples are somewhat poor; this one is better:

[Unit]
description=ipfs p2p daemon
After=network.target
Requires=network.target

[Service]
Type=simple
User=ipfs
RestartSec=1
Restart=always
PermissionsStartOnly=true
Nice=18
StateDirectory=/var/lib/ipfs
Environment=IPFS_PATH=/var/lib/ipfs
Environment=HOME=/var/lib/ipfs
LimitNOFILE=8192
Environment=IPFS_FD_MAX=8192
EnvironmentFile=-/etc/sysconfig/ipfs
StandardOutput=journal
WorkingDirectory=/var/lib/ipfs
ExecStartPre=-adduser --system --group --home /var/lib/ipfs ipfs
ExecStartPre=-mkdir /var/lib/ipfs
ExecStartPre=-/bin/chown ipfs:ipfs /var/lib/ipfs
ExecStartPre=-/bin/chmod ug+rwx /var/lib/ipfs
ExecStartPre=-chpst -u ipfs /usr/local/bin/ipfs init --profile=badgerds
ExecStartPre=-chpst -u ipfs /usr/local/bin/ipfs config profile apply server
ExecStartPre=-chpst -u ipfs /usr/local/bin/ipfs config profile apply local-discovery
ExecStartPre=-chpst -u ipfs /usr/local/bin/ipfs config Datastore.StorageMax "4000GB"
ExecStart=/usr/local/bin/ipfs daemon --enable-namesys-pubsub --enable-pubsub-experiment

[Install]
WantedBy=multi-user.target

@Stebalien
Copy link
Member

I have an initial PR (#5514) to add systemd and socket activation support. I'd like to avoid making the example service file too opinionated unless we provide both a system and a user service file along with instructions.

@feilongfl
Copy link

a sample for archlinux, base on @sneak version

[Unit]
description=ipfs p2p daemon
After=network.target
Requires=network.target

[Service]
Type=simple
User=ipfs
RestartSec=1
Restart=always
PermissionsStartOnly=true
Nice=18
StateDirectory=/home/ipfs
Environment=IPFS_PATH=/home/ipfs
Environment=HOME=/home/ipfs
LimitNOFILE=8192
Environment=IPFS_FD_MAX=8192
EnvironmentFile=-/etc/sysconfig/ipfs
StandardOutput=journal
WorkingDirectory=/home/ipfs
ExecStartPre=-groupadd ipfs
ExecStartPre=-useradd -r -g ipfs -d /home/ipfs ipfs
ExecStartPre=-mkdir /home/ipfs
ExecStartPre=-/bin/chown ipfs:ipfs /home/ipfs
ExecStartPre=-/bin/chmod ug+rwx /home/ipfs
ExecStartPre=-chpst -u ipfs /usr/bin/ipfs init --profile=badgerds
ExecStartPre=-chpst -u ipfs /usr/bin/ipfs config profile apply server
ExecStartPre=-chpst -u ipfs /usr/bin/ipfs config profile apply local-discovery
ExecStartPre=-chpst -u ipfs /usr/bin/ipfs config Datastore.StorageMax "2GB"
ExecStart=/usr/bin/ipfs daemon --enable-namesys-pubsub --enable-pubsub-experiment --enable-gc

[Install]
WantedBy=multi-user.target

@Ericson2314
Copy link

Ericson2314 commented Jun 9, 2020

@Stebalien's #5514 mentioned above he closed, but his #6675 is now merged! See https://github.com/ipfs/go-ipfs/tree/master/misc/systemd for where the files are.

@RubenKelevra
Copy link
Contributor

@Ericson2314 is there a reason why you warm up this old and closed ticket? :)

@Ericson2314
Copy link

I posted here because I landed here while looking for systemd support, the information was out of date, and the situation has improved since. I figured I would by leaving a comment for future searchers, I would save them some trouble.

I usually figure this is good practice (especially when it's good news). And since the issue had been updated with new information before (by an employee of Protocol Labs, no less), I figured it was deemed good practice here to.

@RubenKelevra
Copy link
Contributor

Thanks for pointing this out. The documentation is indeed a bit outdated and should point to the misc/systemd directory.

I created a ticket for this. Feel free to add notes to it, if something is missing:

ipfs-inactive/website#383

@caryyu
Copy link

caryyu commented Jul 18, 2021

Ubuntu 20.04.2 LTS

System-Scoped

/etc/systemd/system/ipfs.service

[Unit]
Description=IPFS Daemon
After=network.target

[Service]
User=ubuntu
Group=ubuntu
Environment=IPFS_PATH=/home/ubuntu/.ipfs
ExecStart=/usr/local/bin/ipfs daemon --init --migrate
StandardOutput=journal
Restart=on-failure
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

sudo systemctl daemon-reload
sudo systemctl start ipfs
sudo systemctl enable ipfs - for auto-start by reboot

User-Scoped

/home/ubuntu/.config/systemd/user/ipfs.service

[Unit]
Description=IPFS Daemon
After=network.target

[Service]
User=ubuntu
Group=ubuntu
Environment=IPFS_PATH=/home/ubuntu/.ipfs
ExecStart=/usr/local/bin/ipfs daemon --init --migrate
StandardOutput=journal
Restart=on-failure
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

systemctl --user daemon-reload
systemctl --user start ipfs

@RubenKelevra
Copy link
Contributor

Hey @caryyu,

you can find the systemd service files for go-ipfs in misc/systemd.

I recommend the hardened version if you don't need FUSE.

@0xAlexS
Copy link

0xAlexS commented Apr 30, 2022

Ubuntu 20.04.2 LTS

System-Scoped

/etc/systemd/system/ipfs.service

[Unit]
Description=IPFS Daemon
After=network.target

[Service]
User=ubuntu
Group=ubuntu
Environment=IPFS_PATH=/home/ubuntu/.ipfs
ExecStart=/usr/local/bin/ipfs daemon --init --migrate
StandardOutput=journal
Restart=on-failure
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

sudo systemctl daemon-reload sudo systemctl start ipfs sudo systemctl enable ipfs - for auto-start by reboot

User-Scoped

/home/ubuntu/.config/systemd/user/ipfs.service

[Unit]
Description=IPFS Daemon
After=network.target

[Service]
User=ubuntu
Group=ubuntu
Environment=IPFS_PATH=/home/ubuntu/.ipfs
ExecStart=/usr/local/bin/ipfs daemon --init --migrate
StandardOutput=journal
Restart=on-failure
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

systemctl --user daemon-reload systemctl --user start ipfs

The IPFS documentation recommends that the daemon be ran under user-scope. The system-scope example could put your system at risk of being compromised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants