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
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
@ctp-tsteenholdt Please remember to squash/rebase.
We already have a bitcoind.service in contrib/init/ - what is the difference with this one, can we avoid duplicating it?
@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.
@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).
Would be good to have an ACK from @TheBlueMatt here.
18 | + echo 19 | + echo "#" 20 | + echo "# The bitcoin user (${BCUSER}) and data dir (${BCHOME})" 21 | + echo "# were left intact." 22 | + echo "#" 23 | + echo "# After backing up all vital data, cleanup can be completed"
Maybe make it explicit that they should check /var/lib/bitcoin for things like wallets?
10 | +[Unit] 11 | +Description=Bitcoin daemon 12 | +After=network.target 13 | + 14 | +[Service] 15 | +ExecStart=/usr/bin/bitcoind -daemon -conf=/etc/bitcoin/bitcoin.conf -pid=/run/bitcoind/bitcoind.pid
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?
12 | override_dh_auto_clean:
13 | if [ -f Makefile ]; then $(MAKE) distclean; fi
14 | 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
15 |
16 | QT=$(shell dpkg-vendor --derives-from Ubuntu && echo qt4 || echo qt5)
17 | +# qt4 is very broken on arm
Can you pull the backporting of existing debian/ contents out into a separate commit to make it easier to track?
Looks good, though I didnt test any of it.
Thanks @TheBlueMatt. Each of your comments make perfect sense and I'll have them all addressed.
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.
@TheBlueMatt can you take another look? Would be good to get this merged, I think.
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.
8 | +BCHOME="/var/lib/bitcoin" 9 | + 10 | +if [ "$1" = "configure" ]; then 11 | + 12 | + # Add bitcoin user/group - this will gracefully abort if the user already exists. 13 | + # A homedir is never created.
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?
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.
Oh, I misread the script, sorry.
@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?
Yea, just pull the stuff from the PPA's debian tar.
Alright - I'm looking in to it...
@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.
9 | @@ -10,5 +10,4 @@ Terminal=false 10 | Type=Application 11 | Icon=bitcoin128 12 | MimeType=x-scheme-handler/bitcoin; 13 | -Categories=Office;Finance;P2P;Network;Qt; 14 | -StartupWMClass=Bitcoin-qt 15 | +Categories=Office;Finance;
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.
@TheBlueMatt is this now ready for merge?
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.
45 | + --no-enable 46 | + 47 | +# Restart after upgrade 48 | +override_dh_systemd_start: 49 | + dh_systemd_start \ 50 | + --restart-after-upgrade
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.
@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!
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).
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...
Looks good modulo the one restart question I had.
utACK 2a87b1b07c5c4f8b9b34747c5f254c2ae1e824bf with or without restart-after-upgrade.
How will this affect systems that don't have/use systemd?
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?
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.
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.
I'm less concerned with merely old distros, as much as ones that have simply rejected the mandatory-systemd nonsense, such as Devuan.
Did that last comment answer your questions?
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.
Err, no, Luke's point is good and would break several PPA-supported releases.
On May 1, 2018 2:52:47 PM UTC, "Wladimir J. van der Laan" notifications@github.com wrote:
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
debiandirectory. Other improvements can be made later.-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/bitcoin/bitcoin/pull/12769#issuecomment-385690313
Oh, hmm, I appears to be wrong, it looks like the dh-systemd package is on trusty, I suppose its fine, then.
Had to revert this, please file again in 2019 (or whenever relevant).
@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?
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)
Okay... Does this mean I should rework the changes to go in the new path then?
Indeed, just cherry-pick the commits and submit them to the other repo.
Thanks. I've created https://github.com/bitcoin-core/packaging/pull/1 with exact same changes...