Skip to content

Conversation

whitslack
Copy link
Contributor

This is an alternative to #22285 to address @luke-jr's concern.

When other initscripts depend on bitcoind, it's because their daemons want to be able to invoke bitcoin-cli or to communicate with bitcoind via RPC. That can't happen until some time after bitcoind has forked into the background. The -startupnotify option was added in 090530c (#15367) to support exactly this use case, so let's use it.

A straightforward and reliable way to wait for bitcoind to invoke its -startupnotify command is to make bitcoind hold a lock on a dummy file and release that lock via the -startupnotify command. The initscript's start_post() function initially marks the service as inactive and forks a subshell process into the background to wait for bitcoind to release the lock file, which will happen when bitcoind either executes the -startupnotify command or dies. After acquiring and releasing the lock, the subshell checks whether the pid file still exists and marks the service as started or stopped appropriately.

When other initscripts depend on bitcoind, it's because their daemons
want to be able to invoke bitcoin-cli or to communicate with bitcoind
via RPC. That can't happen until some time after bitcoind has forked
into the background. The -startupnotify option was added in 090530c
(bitcoin#15367) to support exactly this use case, so let's use it.

A straightforward and reliable way to wait for bitcoind to invoke its
-startupnotify command is to make bitcoind hold a lock on a dummy file
and release that lock via the -startupnotify command. The initscript's
start_post() function initially marks the service as inactive and forks
a subshell process into the background to wait for bitcoind to release
the lock file, which will happen when bitcoind either executes the
-startupnotify command or dies. After acquiring and releasing the lock,
the subshell checks whether the pid file still exists and marks the
service as started or stopped appropriately.
-pid "${BITCOIND_PIDFILE}" \
-conf "${BITCOIND_CONFIGFILE}" \
-datadir "${BITCOIND_DATADIR}" \
-startupnotify "flock -u 3") \
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, one side effect of using startupnotify here is that the user can no longer use it himself...

Maybe we need to fix this to allow multiple -*notify commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely think the -*notify options should stack, but I don't think that's a big concern with respect to this PR. If a user wants something to happen when bitcoind is ready to handle RPC requests, they would just create an initscript that depends on bitcoind and let OpenRC handle the sequencing.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 28, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22285 (contrib/init: (OpenRC) use -startupnotify to wait for startup completion by whitslack)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@whitslack whitslack closed this Jan 14, 2022
@whitslack whitslack deleted the openrc-startupnotify-bkg branch January 14, 2022 08:27
@bitcoin bitcoin locked and limited conversation to collaborators Jan 14, 2023
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.

3 participants