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

Add systemd service to bitcoind in debian package #12769

Merged
merged 2 commits into from May 1, 2018
Merged

Add systemd service to bitcoind in debian package #12769

merged 2 commits into from May 1, 2018

Conversation

ghost
Copy link

@ghost ghost commented Mar 23, 2018

On suggestion from @TheBlueMatt I have updated contrib/debian files to include a systemd service in the bitcoind build. Tested and working on Ubuntu 16.04 and 17.10.

This fixes Issue #12758

@randolf
Copy link
Contributor

randolf commented Mar 23, 2018

@ctp-tsteenholdt Please remember to squash/rebase.

@ghost
Copy link
Author

ghost commented Mar 23, 2018

@randolf That makes total sense. My apologies - looking into it right now...

@ghost ghost closed this Mar 23, 2018
@ghost ghost reopened this Mar 23, 2018
@laanwj
Copy link
Member

laanwj commented Mar 26, 2018

We already have a bitcoind.service in contrib/init/ - what is the difference with this one, can we avoid duplicating it?

@ghost
Copy link
Author

ghost commented Mar 26, 2018

@randolf The pull request should look better now - please let me know if I'm missing something.

@ghost
Copy link
Author

ghost commented Mar 27, 2018

@laanwj I'm completely with you on that question, but I don't think we can feasibly avoid multiple versions of a file like this. The different versions of the bitcoind.service in the contrib/ tree have subtle differences to make them work best for their particular purpose. The differences reflect distro-specifics such as location of environment files, dependency services etc.

Also, building a package for Ubuntu or Debian requires a full copy of the contrib/debian/ folder, including the bitcoind.service file, to allow the packaging helper dh to recognize, treat and install it correctly.

It think distro-specific files are probably better maintained within distro specific folders such as contrib/debian/ or contrib/rpm/, as part of the overall package maintenance for that distro. This avoids possible breakage from a change made for a different distro too.

To underline that the contrib/init/ version is still very relevant, it will be the goto file for people on platforms without a specific package or people who prefer to build from source. This file can be easily adapted to work well on most systems.

Please let me know what you think.

@laanwj
Copy link
Member

laanwj commented Mar 27, 2018

@ctp-tsteenholdt If it is intentional, then IMO it's not a problem. Arguably the debian-specific file is easier to maintain because at least it aims for a specific environment and can be tested there, not 'all distributions in general', which has made the file under contrib/init/ a real pain in practice (see e.g. discussion in #12255).

@ghost
Copy link
Author

ghost commented Mar 27, 2018

@laanwj That's exactly right.

@laanwj
Copy link
Member

laanwj commented Mar 28, 2018

Would be good to have an ACK from @TheBlueMatt here.

Copy link
Contributor

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, though I didnt test any of it.

echo "# The bitcoin user (${BCUSER}) and data dir (${BCHOME})"
echo "# were left intact."
echo "#"
echo "# After backing up all vital data, cleanup can be completed"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make it explicit that they should check /var/lib/bitcoin for things like wallets?

After=network.target

[Service]
ExecStart=/usr/bin/bitcoind -daemon -conf=/etc/bitcoin/bitcoin.conf -pid=/run/bitcoind/bitcoind.pid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be nice to make the datadir explicit so that we dont have /var/lib/bitcoin/.bitcoin and instead just put stuff in /var/lib/bitcoin?


override_dh_auto_clean:
if [ -f Makefile ]; then $(MAKE) distclean; fi
rm -rf Makefile.in aclocal.m4 configure src/Makefile.in src/bitcoin-config.h.in src/build-aux src/qt/Makefile.in src/qt/test/Makefile.in src/test/Makefile.in

QT=$(shell dpkg-vendor --derives-from Ubuntu && echo qt4 || echo qt5)
# qt4 is very broken on arm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pull the backporting of existing debian/ contents out into a separate commit to make it easier to track?

@ghost
Copy link
Author

ghost commented Mar 28, 2018

Thanks @TheBlueMatt. Each of your comments make perfect sense and I'll have them all addressed.

@ghost
Copy link
Author

ghost commented Mar 29, 2018

I've addressed the suggestions made by @TheBlueMatt, run a test dpkg-buildpackage using the updated contrib/debian/ tree and tested that the package changes work as expected, with success.

The commits have been updated to reflect the changes.

@laanwj
Copy link
Member

laanwj commented Apr 7, 2018

@TheBlueMatt can you take another look?
Would be good to get this merged, I think.

@TheBlueMatt
Copy link
Contributor

Hmm, if you're gonna pull some of the debian changes upstream, can you just pull all of them? Especially getting the changelog and other stuff out of sync seems not ideal.

if [ "$1" = "configure" ]; then

# Add bitcoin user/group - this will gracefully abort if the user already exists.
# A homedir is never created.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not create the directory? If its empty it will be deleted on uninstall, but if ther user ever tries to use the service things will simply fail to start, no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this approach is that, if for whatever reason the user has changed ownership or permissions on the /var/lib/bitcoin directory, we don't want to mess with that on operations like reconfigure, update etc.

adduser does not let me specify custom homedir permissions, so I'm using --no-create-home to work around that. A missing home directory becomes a stable indicator that this is a fresh install, making it safe for me to create the directory and set the restrictive default permissions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I misread the script, sorry.

@ghost
Copy link
Author

ghost commented Apr 18, 2018

@TheBlueMatt I'm not sure what you mean by:

Hmm, if you're gonna pull some of the debian changes upstream, can you just pull all of them? Especially getting the changelog and other stuff out of sync seems not ideal.

Upstream in this case would essentially be your PPA right? Or is there somewhere else?

I can certainly take a look at any other differences between this tree and yours and see if it makes sense to include in this PR or create a separate one for getting those in sync? Is this what you mean?

@TheBlueMatt
Copy link
Contributor

TheBlueMatt commented Apr 18, 2018

Yea, just pull the stuff from the PPA's debian tar.

@ghost
Copy link
Author

ghost commented Apr 18, 2018

Alright - I'm looking in to it...

@ghost
Copy link
Author

ghost commented Apr 18, 2018

@TheBlueMatt so I took all the changes from your upstream PPA debian tar and committed them as a single commit. After that, I committed the Systemd changes in a separate commit.

As a precaution I've run a local build and made sure that things still work as expected.

@@ -10,5 +10,4 @@ Terminal=false
Type=Application
Icon=bitcoin128
MimeType=x-scheme-handler/bitcoin;
Categories=Office;Finance;P2P;Network;Qt;
StartupWMClass=Bitcoin-qt
Categories=Office;Finance;
Copy link
Member

@fanquake fanquake Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These additional categories were just added in #12854

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fanquake thanks. I'll get that sorted out here...

ctp-tsteenholdt added 2 commits April 20, 2018 08:31
Adding systemd service for bitcoind, to provide for a simpler
out-of-the-box experience.

Configuration file is /etc/bitcoin/bitcoin.conf. This file is a
copy of the sample configuration file.

The service user 'bitcoin' is added during install. Its homedir
is in '/var/lib/bitcoin'.

bitcoind.service is disabled by default to allow the user to
configure it, before starting it the first time.

On package purge, the 'bitcoin' user as well as its homedir is
left intact, to not accidentally remove a wallet or something of
equal importance. Instead the user is presented with information
on how to perform the cleanup manually, after making sure all
important data has been backed up.
@ghost
Copy link
Author

ghost commented Apr 20, 2018

So I re-resolved the conflict with #12854. This time without nuking the accepted changes of that PR. Sorry about that. Thanks @fanquake for the heads up.

@laanwj
Copy link
Member

laanwj commented Apr 26, 2018

@TheBlueMatt is this now ready for merge?

@ghost
Copy link
Author

ghost commented Apr 26, 2018

Just tested on Ubuntu 18.04, with no issues related to this PR. There is an unrelated issue with the libdb++ version that needs to be sorted out, so I built with --with-incompatible-bdb to test things out.

Copy link
Contributor

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good modulo the one restart question I had.

# Restart after upgrade
override_dh_systemd_start:
dh_systemd_start \
--restart-after-upgrade
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I dont think anyone would be surprised by their bitcoind going down prior to upgrade instead of only being restarted, and this could break eg a lxc VM as you'll get a text file busy error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheBlueMatt, good point.

--restart-after-upgrade is default in dh_systemd_start from compat level 10, so the reason is perhaps best described as emulating modern defaults. I agree that for bitcoind, there should not be any real issues with using the defaults.

I don't quite follow the problems you mention though. As far as I can tell, an upgrade should work perfectly, even when leaving the daemon running during the upgrade. Nothing runtime related is touched during the package upgrade, only the new bitcoind and bitcoin-cli binaries are put into place, making them ready for the late restart. Unless I'm missing something, this should be no different when running in a container?

If you feel there's a risk here, I'll happily remove this!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, if its default whatever, but linux generally refuses to replace binaries on disk if they are running inside of an LXC/docker container (though will happily do so during normal operation).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I've never run into that problem, but haven't really come across a situation where such a setup would be needed. I tend to want to install apps like bitcoind inside my containers, in which case this would not be an issue.

But if I wanted this kind of setup, I imagine I'd leave bitcoind disabled on the host and only start the service inside the container, right?

If this is true, then the host level daemon would never be restarted on upgrade as the service is disabled, causing the restart to be skipped on upgrade. The container on the other hand would keep running the "old" in-memory binary, until it's restarted by some other means.

I could be missing something...

@TheBlueMatt
Copy link
Contributor

utACK 2a87b1b with or without restart-after-upgrade.

@luke-jr
Copy link
Member

luke-jr commented Apr 27, 2018

How will this affect systems that don't have/use systemd?

@ghost
Copy link
Author

ghost commented Apr 28, 2018

@luke-jr this affects only debian-based systems (including Ubuntu) with systemd.

@TheBlueMatt
Copy link
Contributor

I believe @luke-jr's question was "what about older but still supported Debian-based systems that do not have systemd", which is a good one. WIll this not result in them failing to build the packages?

@ghost
Copy link
Author

ghost commented Apr 28, 2018

Older debian systems that are missing the dh-systemd package, will fail to build the packages, yes. I believe the (supported) Debian/Ubuntu versions that are affected by this, are Debian 7 (LTS version is EOL at the end of May 2018) and Ubuntu 14.04 LTS (EOL in April 2019).

I'm running a test on Ubuntu 14.04 right now, to see what kind of issues we're running into on that platform.

@ghost
Copy link
Author

ghost commented Apr 28, 2018

As it turns out, Ubuntu 14.04 LTS actually does have a dh-systemd package and apart from the libdb4.8++-dev build dependency, that was also causing problems on Ubuntu 18.04, the build is working just fine.

Since the distro does not actually use systemd, the included bitcoind.service simply does nothing.

FWIW, Debian 7 also has a dh-systemd package (in the backports repository), so I guess it's the same story there.

@luke-jr
Copy link
Member

luke-jr commented Apr 28, 2018

I'm less concerned with merely old distros, as much as ones that have simply rejected the mandatory-systemd nonsense, such as Devuan.

@ghost
Copy link
Author

ghost commented Apr 28, 2018

@luke-jr to build the package, you'd need to have dh-systemd installed, but you do not need systemd to install or use it. If you don't have systemd on the system, you simply can't use the systemd service configuration that's included here.

@ghost
Copy link
Author

ghost commented May 1, 2018

Did that last comment answer your questions?

@laanwj
Copy link
Member

laanwj commented May 1, 2018

I'm going to merge this as @TheBlueMatt utACKed this - he's the ppa maintainer.
I don't think other distributions are relevant here as this concerns explicitly the debian directory.
Other improvements can be made later.

@laanwj laanwj merged commit 2a87b1b into bitcoin:master May 1, 2018
@TheBlueMatt
Copy link
Contributor

TheBlueMatt commented May 1, 2018 via email

laanwj added a commit that referenced this pull request May 1, 2018
2a87b1b Add systemd service for bitcoind (ctp-tsteenholdt)
9085532 Sync contrib/debian from Matt Corallo's PPA (ctp-tsteenholdt)

Pull request description:

  On suggestion from @TheBlueMatt I have updated `contrib/debian` files to include a systemd service in the `bitcoind` build. Tested and working on Ubuntu 16.04 and 17.10.

  This fixes Issue #12758

Tree-SHA512: b6137fafee940c7410df1242c8716a87f47c5bc60eb8df3ad0184a50c2d67ef3f2728761c742670a0ad546ab6e7ad60472a721350cd6280b3bcbdc582e50ee07
@TheBlueMatt
Copy link
Contributor

Oh, hmm, I appears to be wrong, it looks like the dh-systemd package is on trusty, I suppose its fine, then.

laanwj added a commit that referenced this pull request May 1, 2018
After discussion with Matt on IRC, this is not ready for prime time
until 2019 and shouldn't have been ACKed and merged.

- Revert "Add systemd service for bitcoind"

This reverts commit 2a87b1b.

- Revert "Sync contrib/debian from Matt Corallo's PPA"

This reverts commit 9085532.

Tree-SHA512: 439f4ccc3e196011af448b220adf26b0e653ac589bf4cfbbc276c1500c9d08f209c9d6101e4d232857779d9f25164cfb222ed30e3d63de116f9121e6ebde31c3
@laanwj
Copy link
Member

laanwj commented May 1, 2018

Had to revert this, please file again in 2019 (or whenever relevant).

@ghost
Copy link
Author

ghost commented May 1, 2018

@laanwj, as @TheBlueMatt mentions in his followup, dh-systemd is indeed available on the relevant distributions - It certainly is on all supported versions of Ubuntu, Debian and Devuan. I can't see a reason to hold off on the merge?

@laanwj
Copy link
Member

laanwj commented May 1, 2018

After discussion on IRC we're switching to a different strategy, distribution packaging files will be under this repository from now on:
https://github.com/bitcoin-core/packaging
(see also #13137)

@ghost
Copy link
Author

ghost commented May 1, 2018

Okay... Does this mean I should rework the changes to go in the new path then?

@maflcko
Copy link
Member

maflcko commented May 1, 2018

Indeed, just cherry-pick the commits and submit them to the other repo.

@ghost
Copy link
Author

ghost commented May 2, 2018

Thanks. I've created bitcoin-core/packaging#1 with exact same changes...

stamhe pushed a commit to stamhe/bitcoin that referenced this pull request Jun 27, 2018
After discussion with Matt on IRC, this is not ready for prime time
until 2019 and shouldn't have been ACKed and merged.

- Revert "Add systemd service for bitcoind"

This reverts commit 2a87b1b.

- Revert "Sync contrib/debian from Matt Corallo's PPA"

This reverts commit 9085532.

Tree-SHA512: 439f4ccc3e196011af448b220adf26b0e653ac589bf4cfbbc276c1500c9d08f209c9d6101e4d232857779d9f25164cfb222ed30e3d63de116f9121e6ebde31c3
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants