Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard directories #1805

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changeset/use_standard_directories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
default: major
---

# Use standard locations for application data

Uses standard locations for application data instead of the current directory. This brings `renterd` in line with other system services and makes it easier to manage application data.

#### Linux, FreeBSD, OpenBSD
- Configuration: `/etc/renterd/renterd.yml`
- Data directory: `/var/lib/renterd`

#### macOS
- Configuration: `~/Library/Application Support/renterd.yml`
- Data directory: `~/Library/Application Support/renterd`

#### Windows
- Configuration: `%APPDATA%\SiaFoundation\renterd.yml`
- Data directory: `%APPDATA%\SiaFoundation\renterd`

#### Docker
- Configuration: `/data/renterd.yml`
- Data directory: `/data`
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ENV PGID=0
# Renterd env args
ENV RENTERD_API_PASSWORD=
ENV RENTERD_SEED=
ENV RENTERD_DATA_DIR=/data
ENV RENTERD_CONFIG_FILE=/data/renterd.yml
ENV RENTERD_NETWORK='mainnet'

Expand All @@ -50,4 +51,4 @@ VOLUME [ "/data" ]
USER ${PUID}:${PGID}

# Copy the script and set it as the entrypoint.
ENTRYPOINT ["renterd", "-env", "-http", ":9980", "-s3.address", ":8080", "-dir", "./data"]
ENTRYPOINT ["renterd", "-env", "-http", ":9980", "-s3.address", ":8080"]
60 changes: 30 additions & 30 deletions cmd/renterd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"os"
"path/filepath"

"go.sia.tech/core/types"
"go.sia.tech/coreutils/wallet"
"go.sia.tech/renterd/build"
"go.sia.tech/renterd/config"
"go.sia.tech/renterd/stores/sql/sqlite"
"gopkg.in/yaml.v3"
)
Expand All @@ -19,54 +20,53 @@ func cmdBackup() {
checkFatalError("failed to backup sqlite database", err)
}

func cmdBuildConfig(cfg *config.Config) {
if _, err := os.Stat("renterd.yml"); err == nil {
if !promptYesNo("renterd.yml already exists. Would you like to overwrite it?") {
return
}
func cmdBuildConfig(fp string) {
fmt.Println("renterd Configuration Wizard")
fmt.Println("This wizard will help you configure renterd for the first time.")
fmt.Println("You can always change these settings with the config command or by editing the config file.")

if fp == "" {
fp = configPath()
}

fmt.Println("")
if cfg.Seed != "" {
fmt.Println(wrapANSI("\033[33m", "A wallet seed phrase is already set.", "\033[0m"))
fmt.Println("If you change your wallet seed phrase, your renter will not be able to access Siacoin associated with this wallet.")
fmt.Println("Ensure that you have backed up your wallet seed phrase before continuing.")
if promptYesNo("Would you like to change your wallet seed phrase?") {
setSeedPhrase(cfg)
fmt.Printf("Config Location %q\n", fp)

if _, err := os.Stat(fp); err == nil {
if !promptYesNo(fmt.Sprintf("%q already exists. Would you like to overwrite it?", fp)) {
return
}
} else if !errors.Is(err, os.ErrNotExist) {
checkFatalError("failed to check if config file exists", err)
} else {
setSeedPhrase(cfg)
// ensure the config directory exists
checkFatalError("failed to create config directory", os.MkdirAll(filepath.Dir(fp), 0700))
}

fmt.Println("")
if cfg.HTTP.Password != "" {
fmt.Println(wrapANSI("\033[33m", "An admin password is already set.", "\033[0m"))
fmt.Println("If you change your admin password, you will need to update any scripts or applications that use the admin API.")
if promptYesNo("Would you like to change your admin password?") {
setAPIPassword(cfg)
}
} else {
setAPIPassword(cfg)
}
setDataDirectory()

fmt.Println("")
setS3Config(cfg)
setSeedPhrase()

fmt.Println("")
setAdvancedConfig(cfg)
setAPIPassword()

// write the config file
configPath := "renterd.yml"
if str := os.Getenv("RENTERD_CONFIG_FILE"); str != "" {
configPath = str
}
fmt.Println("")
setS3Config()

f, err := os.Create(configPath)
fmt.Println("")
setAdvancedConfig()

f, err := os.Create(fp)
checkFatalError("Failed to create config file", err)
defer f.Close()

enc := yaml.NewEncoder(f)
defer enc.Close()

checkFatalError("Failed to encode config file", enc.Encode(cfg))
checkFatalError("Failed to sync config file", f.Sync())
}

func cmdSeed() {
Expand Down
Loading
Loading