3

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 --

  1. I built cardano-node by follow this docs precisely. So, even the ghc --version and/or cabal --version is same
  2. 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

  1. Do find . -name cardano-db-sync -executable -type f to find its location
  2. Then, I did symlink (register cardano-db-sync) into /usr/local/bin (or wherever suitable for you), using sudo ln -s ... (or other similar syntax / command).
  3. 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! :)

4
  • 3
    As the main dev on 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 as root, and root does not have access to the cabal executable). Feb 28 at 11:24
  • Hi @ErikdeCastroLopo - thanks for your explanation! Do you mind to explain a bit more about this sentences of yours "I would recommend that you avoid building it every time you run it" - I still not really understand, which part that "build" every time I run which? *sorry, I kinda lost on that part.
    – wandyyd
    Mar 1 at 4:02
  • cabal build ... builds the executable. Every time you run that command the executable gets build. Mar 7 at 3:12
  • Gotcha! Thanks for your kind explanation! :)
    – wandyyd
    Mar 7 at 4:33

1 Answer 1

6

Why are you running cardano-db-sync with cabal? You should just run cardano-db-sync or cardano-db-sync-extended. And another question, more important: why are you running the service as root? This is always a security issue. You should never run a service as root (unless really needed, which is not the case here) or as an user with sudo rights. And cardano-db-sync should be in /usr/local/bin, for example.

I'm posting here my service file and my shell script executed by the service:

# cat /etc/systemd/system/cardano-db-sync.service 
# The Cardano db-sync service (part of systemd)
# file: /etc/systemd/system/cardano-db-sync.service 

[Unit]
Description      = Cardano db-sync service
Wants            = network-online.target
After            = network-online.target 

[Service]
User             = cardano
Type             = simple
WorkingDirectory = /home/cardano/cardano-node
ExecStart        = /bin/bash -c '/home/cardano/cardano-node/bin/db-sync.sh'
KillSignal       = SIGINT
TimeoutStopSec   = 120
LimitNOFILE      = 32768
Restart          = always
RestartSec       = 5

[Install]
WantedBy         = multi-user.target
# cat /home/cardano/cardano-node/bin/db-sync.sh
PGPASSFILE=/home/cardano/cardano-node/config/pgpass-mainnet cardano-db-sync-extended \
    +RTS -N -RTS \
    --config /home/cardano/cardano-node/config/mainnet-db-sync-config.json \
    --socket-path /home/cardano/cardano-node/db/node.socket \
    --state-dir /home/cardano/cardano-node/ledger-state/mainnet \
    --schema-dir /home/cardano/cardano-node/schema/
4
  • Hi! Thanks for your explanation and sample codes. It kinda gives me more explanation. About your question "Why are you running cardano-db-sync with cabal? You should just run cardano-db-sync or cardano-db-sync-extended - it seems I kinda misunderstood the documentation. And, because its last step, I kinda confuse on where can I found the "cardano-db-sync-exe", so, I follow the previous step where it says "... cabal run cardano-db-sync .... "
    – wandyyd
    Mar 1 at 4:15
  • --continue-- About your concern, why I run it as root, it's because the server is a test server, and I still learn things around since I super newbie! Anyway, thanks a lot for that! really means a lot for me to learn! || And "And cardano-db-sync should be in /usr/local/bin" - I don't see that on that folder. I just follow their docs.
    – wandyyd
    Mar 1 at 4:24
  • You are welcome. I am keeping all cardano-related binaries in /usr/local/bin, it's probably the best location for them. Mar 1 at 11:23
  • ohh! I see! I thought it supposed to be there after installation. Thanks for your tips!
    – wandyyd
    Mar 2 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.