-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathservice.go
56 lines (43 loc) · 2.04 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package khatru_pyramid
import (
"github.com/nodetec/rwz/pkg/relays"
"github.com/nodetec/rwz/pkg/utils/configuration"
"github.com/nodetec/rwz/pkg/utils/directories"
"github.com/nodetec/rwz/pkg/utils/files"
"github.com/nodetec/rwz/pkg/utils/systemd"
"github.com/pterm/pterm"
)
// Function to set up the relay service
func SetupRelayService(domain, pubKey, relayContact string) {
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay service...")
// Ensure the data directory exists and set permissions
spinner.UpdateText("Creating data directory...")
directories.CreateDirectory(DataDirPath, 0755)
// Use chown command to set ownership of the data directory to the nostr user
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)
// Ensure the config directory exists and set permissions
spinner.UpdateText("Creating config directory...")
directories.CreateDirectory(ConfigDirPath, 0755)
// Check if the environment file exists and remove it if it does
files.RemoveFile(EnvFilePath)
// Check if the service file exists and remove it if it does
files.RemoveFile(ServiceFilePath)
// Create the environment file
spinner.UpdateText("Creating environment file...")
envFileParams := configuration.EnvFileParams{Domain: domain, PubKey: pubKey, RelayContact: relayContact}
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)
// Set permissions for the environment file
files.SetPermissions(EnvFilePath, 0644)
// Create the systemd service file
spinner.UpdateText("Creating service file...")
serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath}
systemd.CreateServiceFile(ServiceFilePath, ServiceFileTemplate, &serviceFileParams)
// Reload systemd to apply the new service
spinner.UpdateText("Reloading systemd daemon...")
systemd.Reload()
// Enable and start the Nostr relay service
spinner.UpdateText("Enabling and starting service...")
systemd.EnableService(ServiceName)
systemd.StartService(ServiceName)
spinner.Success("Nostr relay service configured")
}