Linux/Ubuntu - Cardano newbie, want to ask things around! :)
At the moment, I'm successfully installed cardano-node and can make it run as a service (pulling data automatically on the background), by following some of these instruction. I only follow some / few steps.
I tried to replicate it into cardano-db-sync
version, so I can do cardano-db-sync automatically on the background. But, it gives some error / issue.
I already make, .sh
and .service
file.
Below is the code for, .sh
file
#!/bin/bash
PGPASSFILE=/cardano/cardano-db-sync/config/pgpass-mainnet
CONFIG=/cardano/cardano-db-sync/config/mainnet-config.yaml
SOCKET_PATH=/cardano/db/node.socket
STATE_DIR=/cardano/cardano-db-sync/ledger-state/mainnet
SCHEMA_DIR=/cardano/cardano-db-sync/schema/
PGPASSFILE=${PGPASSFILE} cabal run cardano-db-sync -- --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}
And for .service
file
# The Cardano DB Sync service (part of systemd)
# file: /etc/systemd/system/cardano-db-sync-run.service
[Unit]
Description = Cardano DB Sync service
Wants = network-online.target
After = network-online.target
[Service]
User = root
Type = simple
WorkingDirectory= /cardano/cardano-db-sync
ExecStart = /bin/bash -c '/cardano/cardano-db-sync-run.sh'
KillSignal=SIGINT
TimeoutStopSec=300
LimitNOFILE=32768
Restart=always
RestartSec=5
SyslogIdentifier=cardano-db-sync
[Install]
WantedBy = multi-user.target
When I test to manually run /bin/bash -c '/cardano/cardano-db-sync-run.sh'
it's working well and I can see some data get into database.
BUT, when I tried to run it as a service, it gives and error. Here's what I did to make it run as a service
> sudo systemctl enable cardano-db-sync-run
> sudo systemctl start cardano-db-sync-run
And then, checking its log by
> journalctl --unit=cardano-db-sync-run --follow
And it shows an error - line 7: cabal: command not found
.
I tried to see and one of my colleague advise me, to use full path of "cabal", since it isn't on /bin
, so I change a bit .sh
file to be
...
...
PGPASSFILE=${PGPASSFILE} /root/.ghcup/bin/cabal run cardano-db-sync -- --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}
Notice, that I change cabal
into /root/.ghcup/bin/cabal
. But, by doing so, it also gives an error message, as shown below
Feb 28 06:40:44 systemd[1]: Started Cardano DB Sync service.
Feb 28 06:40:44 cardano-db-sync[20548]: /cardano/cardano-db-sync
Feb 28 06:40:45 cardano-db-sync[20548]: Warning: Requested index-state 2021-07-02T00:00:00Z is newer than
Feb 28 06:40:45 cardano-db-sync[20548]: 'hackage.haskell.org'! Falling back to older state (2021-07-01T22:06:28Z).
Feb 28 06:40:45 cardano-db-sync[20548]: Resolving dependencies...
Feb 28 06:40:45 cardano-db-sync[20548]: cabal: Could not resolve dependencies:
Feb 28 06:40:45 cardano-db-sync[20548]: [__0] trying: Win32-network-0.1.0.0 (user goal)
Feb 28 06:40:45 cardano-db-sync[20548]: [__1] trying: base-4.9.1.0/installed-4.9.1.0 (dependency of Win32-network)
Feb 28 06:40:45 cardano-db-sync[20548]: [__2] next goal: base-deriving-via (user goal)
Feb 28 06:40:45 cardano-db-sync[20548]: [__2] rejecting: base-deriving-via-0.1.0.0 (conflict:
Feb 28 06:40:45 cardano-db-sync[20548]: base==4.9.1.0/installed-4.9.1.0, base-deriving-via => base>=4.14)
Feb 28 06:40:45 cardano-db-sync[20548]: [__2] fail (backjumping, conflict set: base, base-deriving-via)
Feb 28 06:40:45 cardano-db-sync[20548]: After searching the rest of the dependency tree exhaustively, these were the
Feb 28 06:40:45 cardano-db-sync[20548]: goals I've had most trouble fulfilling: base, Win32-network, base-deriving-via
Feb 28 06:40:45 systemd[1]: cardano-db-sync-run.service: Main process exited, code=exited, status=1/FAILURE
Feb 28 06:40:45 systemd[1]: cardano-db-sync-run.service: Failed with result 'exit-code'.
Again, I already try to run it manually, using /bin/bash -c '/cardano/cardano-db-sync-run.sh'
and it works well, BUT, only when I make it run as a service, it shows that error.
My guess is that "cabal" isn't really recognized.
Any suggestion on why it failed?
PS --
- I built cardano-node by follow this docs precisely. So, even the
ghc --version
and/orcabal --version
is same - cardano-db-sync that I built is using Cabal (ghc stuffs), not using Nix / docker.
Thanks in advance!
*Edit #1 - after read the comments and replies from Eric de Castro Lopo and George - APEX Stake Pool, I got question
Do I need to wait this part to be done? So, I can make cardano-db-sync as a service?
PGPASSFILE=config/pgpass-mainnet cabal run cardano-db-sync --
--config config/mainnet-config.yaml
--socket-path ../cardano-node/state-node-mainnet/node.socket
--state-dir ledger-state/mainnet
--schema-dir schema/
*It's written on the docs
*Edit #2 - after checking more
Question from *Edit #1 - can be ignored, but for someone who looking for the answer, the answer is didn't need to. Detail can be seen on comment / replies by others.
Anyway, finally I can make it work as service. And as per guidance from Eric de Castro Lopo and George - APEX Stake Pool, seems I mistakenly put the syntax/command on .sh
file as mentioned. Thanks!
In-case someone need, the workaround I did is to make a symlink of the executable
file of cardano-db-sync
- Do
find . -name cardano-db-sync -executable -type f
to find its location - Then, I did symlink (register
cardano-db-sync
) into /usr/local/bin (or wherever suitable for you), usingsudo ln -s ...
(or other similar syntax / command). - And finally, on
.sh
file, I change this part... cabal run cardano-db-sync -- ...
into... cardano-db-sync -- ...
Anyway, I will mark George - APEX Stake Pool's answer as it's the closest hint for me.
And, sorry Eric de Castro Lopo that I couldn't upvote your comment, as it's helpful too for me! Need +15 rep to upvote your comment :(
Thanks for your time! :)
cardano-db-sync
I would recommend that you avoid building it every time you run it. Build it once and then install it (will probably need to be manually, as root) and then it should all work (the reason it does currently work is that the service is running asroot
, androot
does not have access to thecabal
executable).cabal build ...
builds the executable. Every time you run that command the executable gets build.