Does Daml Sandbox Script provide any return status, looking for suggestions

Trying to automate a few processes here in a bash script to

  1. run daml sandbox, and once the dars are uploaded
  2. run daml json api
  3. run the daml script to run the init script, which will populate parties
  4. run a few triggers.

Currently I have the below code (scroll down a bit). I’m using wait 10, which does the job, but it’s a workaround, as the sandbox process is not guaranteed to take 10 seconds, and I need it to be running before I populate the parties.

Daml sandbox doesn’t output any completion status does it? apart from indicating Canton setup is complete or something like that.

the start script below:

daml sandbox --dar main/Asset/asset.dar --dar main/User/user.dar --dar main/Account/account.dar &
sleep 10
daml json-api --config json-api-app.conf &
echo "launching ledger init script"
daml script --ledger-host localhost --ledger-port 6865 --dar main/account/account.dar --script-name Init:setup &
sleep 10
echo "ledger init script finished"
echo "starting Daml triggers"
daml trigger --dar triggers/triggers.dar \
             --trigger-name SendAssetHoldingAccountInviteTrigger:sendAssetHoldingAccountInviteTrigger \
             --ledger-host localhost \
             --ledger-port 6865 \
             --ledger-user "admin" &
daml trigger --dar triggers/triggers.dar \
             --trigger-name AcceptAirdropRequestTrigger:acceptAirdropRequestTrigger \
             --ledger-host localhost \
             --ledger-port 6865 \
             --ledger-user "admin" &
daml trigger --dar triggers/triggers.dar \
             --trigger-name AcceptAssetInviteTrigger:acceptAssetInviteTrigger \
             --ledger-host localhost \
             --ledger-port 6865 \
             --ledger-user "admin" &
daml trigger --dar triggers/triggers.dar \
             --trigger-name AcceptSwapTrigger:acceptSwapTrigger \
             --ledger-host localhost \
             --ledger-port 6865 \
             --ledger-user "admin" &
wait

Reason for wanting to add a bit of convenience is currently, to run the app locally we need to

  1. build dars
  2. codgen
  3. cd ui, npm i
  4. run daml sandbox
  5. run json-api server
  6. run daml script to populate parties
  7. run triggers (there are 4, so then its 4 separate terminal windows)

Ideally, we can just have one script that does everything.

1 Like

Part of these steps is performed by the daml start command, except for the triggers. You can specify the init script in the daml yaml file.

There are two main options here:

  1. daml start has an --on-start option. You can specify the script there that you want to run once sandbox is up.
  2. If you don’t want to use daml start, you can use the --port-file option to daml sandbox and wait for that file to be created. This also works nicely in tests where you can start sandbox on port 0 to use any free port and then read the port provided by the OS from that file.
3 Likes

You can run a Daml script of a Bash script in this way? I guess for launching a Trigger you would need a Bash script. If just a Daml script, how is this option different from the init script specified in the daml.yaml file?

It runs a bash script not a daml script so you can put whatever you want in there.

2 Likes

Thank you Moritz, that’s very useful.

1 Like

Thanks for this! Will try out the --port-file option.

Just to clarify, does the --port-file option, is it supposed to create a log folder? with canton_errors.log and canton.log? and as long as this file is generated, it means that the sandbox has been set up?

Before using the portfile option, I would sometimes see this directory being created at the root of my folder. (not sure why or how)

Actually, it seems like that log directory is always generated when I start sandbox.

Yes the log directory is completely independent of this. --port-file yourportfilehere only creates yourportfilehere.

1 Like