running Bitcoin with systemd (Xenial) #13344

issue HashUnlimited openend this issue on May 30, 2018
  1. HashUnlimited commented at 10:35 am on May 30, 2018: contributor

    In the process of upgrading my servers to xenial, I am struggling to get the services installed. I am not really sure if there are some limitations, I am overlooking the obvious or the documentation isn’t accurate enough for fresh-on-systemd’s like me (used to the good old init.d).

    • Bitcoin 0.16 (release, some cherry-picks) (compiled as root)
    • added user bitcoin sudo adduser --system --group --no-create-home bitcoin
    • created /etc/bitcoin/bitcoin.conf and chowned to user bitcoin
    • created /var/lib/bitcoind and chowned to user bitcoin
    • created /lib/systemd/system/bitcoin.service

    Now first of all, I got the binaries in /usr/local/bin/ -> that should be ok, all accessible, just adjust bitcoin.service. Next one, it’s complaining it can’t do anything with MemoryDenyWriteExecute=true -> still ok, comment out. The real problem is that it seems to ignore the command line options. No -daemon, no -conf, no -pidfile seems in fact to be executed, just the plain bitcoind. Now I could create a home for bitcoin but the aim is to run multiple instances so that workaround is not an option.

  2. fanquake added the label Linux/Unix on May 30, 2018
  3. laanwj commented at 12:10 pm on June 1, 2018: member
    Ping @Flowdalic
  4. HashUnlimited commented at 1:10 pm on June 1, 2018: contributor
    Short update: was trying around two days trying all tricks that Dr. Google had on stock. There are reports that passing the args as environmental variable in might work in Fedora, no success in Ubuntu. Imho the perfectly usable solution would support calling the executable with %i do one could for example systemctl bitcoind@conf1.service
  5. Flowdalic commented at 10:34 am on June 2, 2018: contributor

    Next one, it’s complaining it can’t do anything with MemoryDenyWriteExecute=true -> still ok, comment out.

    Could you elaborate on that a bit? Who is complaining? What is the exact message you see and where do you see it? What is the output of systemctl status bitcoind if the service is stoped and started?

    added user bitcoin sudo adduser –system –group –no-create-home bitcoin

    That could be one issue: The systemd file expects the bitcoin user to have a home directory, potentially at /var/lib/bitcoin. It depends on how your bitcoin.conf looks like. Could you show it to us?

  6. HashUnlimited commented at 3:13 pm on June 2, 2018: contributor

    Alright, we are getting

    [/lib/systemd/system/bitcoin.service:41] Unknown lvalue ‘MemoryDenyWriteExecute’ in section ‘Service’

    The bitcoin.conf contains the datadir=/var/lib/bitcoin so there shouldn’t be an issue. Except it doesn’t know about the conf because it’s not taking the correct conf.

    The result of my research is, that the line

    ExecStart=/usr/bin/bitcoind -daemon -conf=/etc/bitcoin/bitcoin.conf -pid=/run/bitcoind/bitcoind.pid

    can’t ever work correctly because systemd will think the arguments are for systemd itself and for sure not passing them through to bitcoind. So it is just staring a plain bitcoind which is then looking for it’s home dir in /hone/bitcoin/ but we didn’t create one for our poor little process simply because we want it to use /var/lib/

  7. Flowdalic commented at 9:13 am on June 3, 2018: contributor

    Alright, we are getting

    [/lib/systemd/system/bitcoin.service:41] Unknown lvalue ‘MemoryDenyWriteExecute’ in section ‘Service’

    Indeed, systemd in Ubuntu 16.04 does appear to be to old to support this option. We probably should add a comment to the shipped systemd service file explaining the situation that it requires systemd >= 231.

    The bitcoin.conf contains the datadir=/var/lib/bitcoin so there shouldn’t be an issue.

    Right, that appears to be OK then.

    The result of my research is, that the line

    ExecStart=/usr/bin/bitcoind -daemon -conf=/etc/bitcoin/bitcoin.conf -pid=/run/bitcoind/bitcoind.pid

    can’t ever work correctly because systemd will think the arguments are for systemd

    Could you share the references of your research which lead you to that conclusion? As far as I can tell the ExecStart rvalue is sound and works as intended. This is for example the truncated output from one of my bitcoind boxes systemctl status bitcoind:

    0   CGroup: /system.slice/bitcoind.service
    1           └─230 /usr/bin/bitcoind -daemon -conf=/etc/bitcoin/bitcoin.conf -pid=/run/bitcoind/bitcoind.>
    

    How does your output look like?

  8. HashUnlimited commented at 9:01 am on June 4, 2018: contributor

    The first clue about what is going on came from Stackexchange (as usual). There are several similar inquiries around which are all claiming that a workaround is needed to pass arguments to a systemd service. It also appears that Xenial (or at least the deployment I got there) is extremely restrictive because I couldn’t get any workaround I found to do the job.

    The folder and permission setup must be all correct because just running the ExecStart content from command line is just doing as expected.

    Unfortunately I can’t get to a valid output of systemctl status bitcoind.service unless I create a home dir for the user bitcoin. Tbh I don’t want to do this here on the production environment just to prove that we are not taking the arguments as with the standard line the log looks like

    – Unit bitcoin.service has begun starting up. Jun 04 04:35:21 FAILOVER bitcoind[24073]: ************************ Jun 04 04:35:21 FAILOVER bitcoind[24073]: EXCEPTION: N5boost10filesystem16filesystem_errorE Jun 04 04:35:21 FAILOVER bitcoind[24073]: boost::filesystem::create_directories: Permission denied: “/home/bitcoin”

    To me that already means we are ignoring the -conf=/etc/bitcoin/bitcoin.conf argument

  9. ken2812221 commented at 9:35 am on June 4, 2018: contributor
    @HashUnlimited Did you specify -datadir?
  10. HashUnlimited commented at 10:06 am on June 4, 2018: contributor
    yep, in bitcoin.conf
  11. Flowdalic commented at 1:37 pm on June 4, 2018: contributor

    To me that already means we are ignoring the -conf=/etc/bitcoin/bitcoin.conf argument

    Or it means that bitcoind tries to do something in $HOME even before reading its configuration file. Which results do you get if you create the user’s home?

  12. HashUnlimited commented at 1:43 pm on June 4, 2018: contributor
    In that case it was taking everything including the .conf from its home folder. Creating a user and a home folder for each instance would be a workaround but then I need a sudo to monitor the processes.
  13. damsy20 commented at 3:49 pm on June 9, 2018: none
    hi
  14. damsy20 commented at 3:50 pm on June 9, 2018: none
    please am using this bitcoin for the time,
  15. HashUnlimited commented at 2:55 pm on June 20, 2018: contributor
    Trying around (messed up the second server cluster in the meanwhile) imho the best solution would be to accept a single argument passed by systemd without the “-” but just pointing to the config. That way we could even make use of descriptors, for example make install test where test is the appendix to the system@.service passed by %i and we are calling bitcoind –cd /etc/bitcoin/%i/ –config %i.conf
  16. HashUnlimited commented at 2:58 pm on June 20, 2018: contributor

    Example from OpenVPN:

     0[Unit]
     1Description=OpenVPN Robust And Highly Flexible Tunneling Application On %I
     2After=network.target
     3
     4[Service]
     5PrivateTmp=true
     6Type=forking
     7PIDFile=/var/run/openvpn/%i.pid
     8ExecStart=/usr/sbin/openvpn --daemon --writepid /var/run/openvpn/%i.pid --cd /etc/openvpn/ --config %i.conf
     9
    10[Install]
    11WantedBy=multi-user.target
    

    edit: note that the daemomizing is done by systemd in that case, that’s something to keep in mind as well as the bitcoin way is deprecated in general (OSX I think since 3 years at least)

  17. MarcoFalke commented at 1:49 am on April 26, 2020: member
    Is this still an issue with a recent version of Bitcoin Core? If yes, what are the steps to reproduce?
  18. MarcoFalke closed this on Apr 26, 2020

  19. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-18 19:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me