diff --git a/README.md b/README.md index 7e8fbc9..8e5306a 100644 --- a/README.md +++ b/README.md @@ -245,46 +245,26 @@ 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: @@ -292,10 +272,11 @@ commands: 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 diff --git a/cmd/server/main.go b/cmd/server/main.go index 0ddbf68..6cabe55 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -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") @@ -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() @@ -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() @@ -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("") @@ -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() { @@ -312,6 +325,7 @@ func showServiceLogs() { fmt.Println(entry) } } + func showActionLogs() { logs, err := logging.GetActionLogs(logDuration) if err != nil { @@ -323,3 +337,9 @@ func showActionLogs() { fmt.Println(entry) } } + +func printVersion() { + fmt.Println("") + fmt.Printf("NanoDNS Version: %s\n", version) + fmt.Println("") +} diff --git a/docs/assets/md/terminal.md b/docs/assets/md/terminal.md index 8be332d..6ed7356 100644 --- a/docs/assets/md/terminal.md +++ b/docs/assets/md/terminal.md @@ -20,6 +20,7 @@ nanodns --help ``` ``` + Usage: nanodns [command | options] commands: @@ -27,9 +28,9 @@ commands: 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 ```