Skip to content

Commit

Permalink
fixes to install script and cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mguptahub committed Nov 1, 2024
1 parent 0af156b commit 37adef9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
39 changes: 10 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,57 +245,38 @@ For detailed instructions on deploying NanoDNS in Kubernetes, see our [Kubernete
## Running Without Docker Compose
### Set Environment Variables
> You can also use `.env` file with all variables. File must be in same folder as binary
Install using the script
```bash
# Set service environment variables
export DNS_PORT=10053
export DNS_RELAY_SERVERS=8.8.8.8:53,1.1.1.1:53
# Logging Configuration (optional)
export LOG_DIR="/tmp/log/nanodns"
export SERVICE_LOG="service.log"
export ACTION_LOG="actions.log"
export MAX_LOG_SIZE=1048576 # 1MB
export MAX_LOG_BACKUPS=5
# Set DNS Records environment variables
export A_REC1=app.example.com|10.10.0.7
export TXT_REC1=example.com|v=spf1 include:_spf.example.com ~all
curl -fsSL https://nanodns.mguptahub.com/install.sh | sh -s -- --install
```

### Start server as daemon
Start using the script

```bash
./nanodns start
# Check the values in /usr/local/share/nanodns.env before starting
nanodns start
```

### Start server as current process

```bash
./nanodns
Help Command
```
nanodns --help
```

### CLI Usage

```bash
./nanodns --help
```
```bash
Usage: nanodns [command | options]
commands:
start Run the binary as a daemon
stop Stop the running daemon service
status Show service status
logs Show service logs
logs -a Show action logs
options:
-v | --version Show the binary version
-a | --action-logs Show the action logs. This works with the logs command
-h | --help Show the help information
```

## Testing Records
Expand Down
48 changes: 34 additions & 14 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ func init() {

flag.BoolVar(&startService, "start", false, "Run the binary as a daemon")
flag.BoolVar(&stopService, "stop", false, "Stop the running daemon service")
flag.BoolVar(&showStatus, "status", false, "Show service status")
flag.BoolVar(&showVersion, "version", false, "Show the binary version")
flag.BoolVar(&showVersion, "v", false, "Show the binary version (short)")
flag.BoolVar(&showHelp, "help", false, "Shows help information")
flag.BoolVar(&showStatus, "status", false, "Show service status")
flag.BoolVar(&showHelp, "h", false, "Shows help information (short)")

flag.BoolVar(&showLogs, "logs", false, "Show the logs")

Expand All @@ -53,10 +54,11 @@ func init() {
fmt.Println(" stop Stop the running daemon service")
fmt.Println(" status Show service status")
fmt.Println(" logs Show service logs")
fmt.Println(" logs -a Show action logs")
fmt.Println("")
fmt.Println("options:")
fmt.Println(" -v | --version Show the binary version")
fmt.Println(" -a | --action-logs Show the action logs. This works with the logs command")
fmt.Println(" -h | --help Show the help information")
}

config.Initialize()
Expand All @@ -68,7 +70,9 @@ func init() {
}

func main() {
if len(os.Args) > 1 {
flag.Parse()
// fmt.Println(flag.Args())
if len(flag.Args()) > 0 {
switch flag.Arg(0) {
case "start":
startDaemon()
Expand All @@ -79,28 +83,26 @@ func main() {
case "status":
checkServiceStatus()
return
case "logs", "log":
case "logs":
showSelectiveLogs()
return
case "help":
flag.Usage()
return
case "version", "v":
printVersion()
return
default:
flag.Usage()
return
}
}
flag.Parse()

if showHelp {
flag.Usage()
return
}

if showVersion {
fmt.Println("")
fmt.Printf("NanoDNS Version: %s\n", version)
fmt.Println("")
return
}

if startService {
if checkIfRunning() {
fmt.Println("")
Expand All @@ -125,8 +127,19 @@ func main() {
return
}

// Regular server startup if no flags are provided
startDNSServer()
if showLogs {
showServiceLogs()
return
}

if showVersion {
printVersion()
return
}

if len(os.Args) == 1 {
startDNSServer()
}
}

func startDNSServer() {
Expand Down Expand Up @@ -312,6 +325,7 @@ func showServiceLogs() {
fmt.Println(entry)
}
}

func showActionLogs() {
logs, err := logging.GetActionLogs(logDuration)
if err != nil {
Expand All @@ -323,3 +337,9 @@ func showActionLogs() {
fmt.Println(entry)
}
}

func printVersion() {
fmt.Println("")
fmt.Printf("NanoDNS Version: %s\n", version)
fmt.Println("")
}
5 changes: 3 additions & 2 deletions docs/assets/md/terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ nanodns --help
```

```
Usage: nanodns [command | options]
commands:
start Run the binary as a daemon
stop Stop the running daemon service
status Show service status
logs Show service logs
logs -a Show action logs
options:
-v | --version Show the binary version
-a | --action-logs Show the action logs. This works with the logs command
-h | --help Show the help information
```

0 comments on commit 37adef9

Please sign in to comment.