Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
add systemd unit
Browse files Browse the repository at this point in the history
  • Loading branch information
dkackman committed Nov 19, 2023
1 parent 86de65f commit 5a820d2
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
21 changes: 19 additions & 2 deletions README.md
Expand Up @@ -2,7 +2,6 @@

[![.NET](https://github.com/dkackman/DlMirrorSync/actions/workflows/dotnet.yml/badge.svg)](https://github.com/dkackman/DlMirrorSync/actions/workflows/dotnet.yml)


This is a utility service that will synchronize the list of chia data layer singletons from [datalayer.storage](https://api.datalayer.storage/mirrors/v1/list_all) to the local chia node. By running this tool, the local node will subscribe to and mirror all of the `datalayer.storage` singletons. This includes a transaction fee for each and devoting 0.0003 XCH per mirror, so be sure you are ready to do this.

Can either be run from code, from built binaries in [the latest release](https://github.com/dkackman/DlMirrorSync/releases/), or as a windows service.
Expand All @@ -21,10 +20,28 @@ To manually install as a windows service run `./install.ps1` from an elevated te

## Run

If you have installed as a service there is nothing else you need to do. The sync will happen immediately when the service starts and once a day there after.
### Command Line

If you are running the single file or standalone versions you can run the following command to sync the singletons:

```bash
./DlMirrorSync ["optional path to chia config"]
```

### Install As a Service

First build the binaries by running `publish.ps1` which will build single file and standalone binaries for windows, linux, and os-x. Outputs will be placed in the `publish` folder. Then run the following commands to install the service:

#### Windows

To manually install as a windows service run `./install.ps1` from an elevated terminal.

#### Linux

_work in progress_

To install as a `systemd` service run `sudo bash install.sh`

#### OS-X

TBD
26 changes: 26 additions & 0 deletions dlsync.service
@@ -0,0 +1,26 @@
## Data Layer Mirror Sync
## make sure to set the run as user by replacing USERNAME with your username

[Unit]
Description=Data Layer Mirror Sync Service
After=network.target

[Service]
# assumes that the built executable and appsettings.json is in /usr/local/bin/DlMirrorSync/
WorkingDirectory=/usr/local/bin/dlsync

# modify as appropriate to use the dll
ExecStart=/usr/local/bin/dlsync/DlMirrorSync /home/USERNAME/.chia/mainnet/config/config.yaml
#ExecStart=/usr/bin/dotnet /path/to/your/app/DlMirrorSync.dll

Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-DlMirrorSync
User=USERNAME
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target
26 changes: 26 additions & 0 deletions install.sh
@@ -0,0 +1,26 @@
#!/bin/bash

# run with bash install.sh (not sh install.sh)

set -o errexit

# Create the destination directory if it doesn't exist
sudo mkdir -p /usr/local/bin/dlsync
# and copy the standa lone binarty to it
sudo cp -r ./publish/standalone/linux-x64/* /usr/local/bin/dlsync/

# Get the directory of the current script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# Get the username of the logged in user
# the service will run as the installing user
# change this line to run as a different user
USERNAME=$(whoami)

# Replace all instances of 'USERNAME' with the runas user's name

# in 'dlsync.service' and save as '/etc/systemd/system/dlsync.service'
sudo sed "s/USERNAME/$USERNAME/g" "$DIR/dlsync.service" > "/etc/systemd/system/dlsync.service"
sudo systemctl start dlsync
sudo systemctl start dlsync
sudo systemctl enable dlsync

0 comments on commit 5a820d2

Please sign in to comment.