How to run grin-wallet as daemon

I am trying to create a systemd service that automatically starts grin-wallet in listen mode. Is there an option to run as daemon or detach?

I don’t see anything like this in the help menu. Does anyone have a work around they use?

Currently you need to use linux / windows tool, like systemd or any other process monitoring solution to do this.

The grin-wallet itself does not support this currently to run as a daemon.

For example running a grin-node:

Description=Grin node
After=network.target

[Service]
WorkingDirectory=/opt/grin/server/
User=root
Group=root
PrivateDevices=yes
Type=simple
ExecReload="/bin/kill -HUP $MAINPID"
KillMode=mixed
KillSignal=SIGTERM
TimeoutStopSec=60
ExecStart=/opt/grin/server/grin server --config_file /opt/grin/server/grin-server.toml run
Restart=on-failure
RestartSec=30

[Install]
WantedBy=multi-user.target
Alias=grin.service

Thank you. Yes, I have a systemd service running the node. I was hoping to create a service running the wallet listener too.

We should give it some thoughts, as I am also running Grinnode.live wallet listener but this runs as a background process which is a manual process.

I did want it to be a manual process as the wallet is password protected and it needs to be entered upon restart of the wallet.

1 Like

Hmm, I bet our needs are similar.

I’m trying to set up an always-on mining node, which requires an active wallet. I periodically transfer the mining rewards to a “colder” wallet, so this wallet never accumulates much money. So i’m less concerned about its security, but need it to be reliably online

1 Like

Once you start scripting, I would strongly suggest to restart the wallet every X-amount of time.
Probably a good idea to do it weekly or even less.

I have to restart the wallet from time to time if the checks do fail: https://grinnode.live/global-health-check

If you not concerned you could also run it as systemd just send the password as an argument, e.g:

##
## Create a new Wallet
## 
grin@vmtest003_$:/tmp/foo$ grin-wallet-api -t /tmp/foo/ init
20230120 14:28:54.525 ERROR grin_wallet_impls::node_clients::http - Error calling get_version: Request error: Cannot make request: error sending request for url (http://127.0.0.1:3413/v2/foreign): error trying to connect: tcp connect error: Connection refused (os error 111)
20230120 14:28:54.525 ERROR grin_wallet_impls::node_clients::http - Unable to contact Node to get version info: Client Callback Error: Error calling get_version: Request error: Cannot make request: error sending request for url (http://127.0.0.1:3413/v2/foreign): error trying to connect: tcp connect error: Connection refused (os error 111)
Please enter a password for your new wallet
Password: 
Confirm Password: 
20230120 14:28:59.582 WARN grin_wallet_impls::lifecycle::seed - Generating wallet seed file at: /tmp/foo/wallet_data/wallet.seed
Your recovery phrase is:

middle milk frown all rabbit good differ under music proud sense tobacco beach foot able vicious birth frost wear sphere eye exhaust rice gaze

Please back-up these words in a non-digital format.
Command 'init' completed successfully

##
## Start wallet manually entering password manually
## 
grin@vmtest003_$:/tmp/foo$ grin-wallet-api -t /tmp/foo/ listen
20230120 14:29:10.491 ERROR grin_wallet_impls::node_clients::http - Error calling get_version: Request error: Cannot make request: error sending request for url (http://127.0.0.1:3413/v2/foreign): error trying to connect: tcp connect error: Connection refused (os error 111)
20230120 14:29:10.491 ERROR grin_wallet_impls::node_clients::http - Unable to contact Node to get version info: Client Callback Error: Error calling get_version: Request error: Cannot make request: error sending request for url (http://127.0.0.1:3413/v2/foreign): error trying to connect: tcp connect error: Connection refused (os error 111)
Password: 
20230120 14:29:12.356 WARN grin_wallet_controller::controller - Starting Tor Hidden Service for API listener at address pwrbyn2lfpswc3afthr7v6cjzn7mci7mlhq4lgmpoxbmfzsdaibfnryd, binding to 127.0.0.1:3415
^C


##
## Create password file
## 
grin@vmtest003_$:/tmp/foo$ vim password.file

##
## Start wallet using the password file without entering it
## 
grin@vmtest003_$:/tmp/foo$ grin-wallet-api -t /tmp/foo/ --pass `cat /tmp/foo/password.file` listen

20230120 14:29:55.446 ERROR grin_wallet_impls::node_clients::http - Error calling get_version: Request error: Cannot make request: error sending request for url (http://127.0.0.1:3413/v2/foreign): error trying to connect: tcp connect error: Connection refused (os error 111)
20230120 14:29:55.446 ERROR grin_wallet_impls::node_clients::http - Unable to contact Node to get version info: Client Callback Error: Error calling get_version: Request error: Cannot make request: error sending request for url (http://127.0.0.1:3413/v2/foreign): error trying to connect: tcp connect error: Connection refused (os error 111)
20230120 14:29:55.485 WARN grin_wallet_controller::controller - Starting Tor Hidden Service for API listener at address pwrbyn2lfpswc3afthr7v6cjzn7mci7mlhq4lgmpoxbmfzsdaibfnryd, binding to 127.0.0.1:3415
20230120 14:30:13.341 WARN grin_wallet_controller::controller - Starting HTTP Foreign listener API server at 127.0.0.1:3415.
20230120 14:30:13.342 WARN grin_wallet_controller::controller - HTTP Foreign listener started.
20230120 14:30:13.342 WARN grin_wallet_controller::controller - Slatepack Address is: grin10k3pcd6t90jkzmq9n83l47zfedlvzglvt8sutxv0whpv9ejrqgpqcyvfdq
^C

##
## Password file
## 
grin@vmtest003_$:/tmp/foo$ cat password.file 
test

##
## date
## 
grin@vmtest003_$:/tmp/foo$ date
Fr 20 Jan 2023 14:30:26 CET

##
## Aliases which where used in this script
## 
_$ type grin-wallet-api 
grin-wallet-api is aliased to `grin-wallet --api_server_address "https://grinnode.live"'

As you can see you can easily use this in any systemd script, this was just the manual process for you to follow along.

1 Like

I tried this, but the wallet process would hang when starting systemd… although perhaps I had something else messed up. I’ll give this another shot. Thanks for the tips!

I’m curious why? I’ve run mine for almost a year without restarting, just fine.

I have no idea to be honest. Just our monitoring shows the wallet is not reachable from the outside (TOR) and we have to restart it. The wallet process itself keeps running however long you want, but the reachability of your wallet over TOR is dropping from time to time.

You can test your wallet using https://grinnode.live/tools/wallet-checker if you like and see if its reachable.

1 Like