Browse Source

export config command. README made useful. More admin use cases.

Frederic G. MARAND 5 years ago
parent
commit
bf466912c5
5 changed files with 117 additions and 9 deletions
  1. 71 0
      README.md
  2. 29 0
      cmd/kurzd/export_config.go
  3. 3 3
      cmd/kurzd/kurzd.go
  4. 6 6
      doc/use_cases/ops/ops1.md
  5. 8 0
      doc/use_cases/ops/ops2.md

+ 71 - 0
README.md

@@ -9,3 +9,74 @@ _Kurz_ is yet another URL shortener.
   * vanity domain support
   * usage statistics
 
+
+# Installing
+
+1. Download the Kurz server to `$GOPATH/bin`
+    ```bash
+    go get code.osinet.fr/fgm/kurz/cmd/kurzd
+    ```
+1. Download the Kurz client to `$GOPATH/bin`
+    ```bash
+    go get code.osinet.fr/fgm/kurz/cmd/kurz
+    ```
+1. Configure a MySQL database for Kurz, say `osinet_kurz` 
+1. Load the Kurz schema to the database:
+    ```bash
+    mysql -u<user> -p<password> osinet_kurz -e "source data/schema.sql;"
+    ```
+1. Create the Kurz configuration
+    ```bash
+    mkdir ~/.kurz
+    cp <kurz dir>/cmd/kurzd/dist.config.yml ~/.kurz/config.yml
+    vi ~/.kurz/config.yml
+1. Edit the configuration and save it. 
+1. Discover the server syntax:
+    ```bash
+    kurzd help
+    ```
+
+
+# Runnning the Kurz server
+
+```bash
+kurzd
+```
+
+
+# Operating the Kurz server
+## Backing up
+
+```bash
+kurzd export config > some_config_backup_file.yml
+kurzd export content > some_content_backup_file.yml
+```
+
+This will need some automation, like cron, to trigger backups and ensure backups
+rotation, as well as removal on uninstall.
+
+
+## Logging
+
+Kurzd [logs to stdout], so any production deployment will need to set up logs
+acquisition and storage, with rotation, and remove them on uninstall. This is
+normally part of a SystemD - or equivalent - service configuration.
+
+[logs to stdout]: https://12factor.net/logs
+ 
+
+# Uninstalling
+
+1. Drop the Kurz database
+    ```bash
+    mysql -u<user> -p<password> -e "drop database osinet_kurz;"
+    ```
+1. If the database used a specific user/password, remove them from the database server
+1. Remove the Kurz configuration
+    ```bash
+    rm ~/.kurz/config.yml
+    ```
+1. Remove Kurz binaries (assuming an single-component `$GOPATH`)
+    ```bash
+    rm $GOPATH/bin/kurz*
+    ```

+ 29 - 0
cmd/kurzd/export_config.go

@@ -0,0 +1,29 @@
+package main
+
+import (
+	"fmt"
+	"github.com/spf13/viper"
+
+	"github.com/spf13/cobra"
+	"gopkg.in/yaml.v2"
+)
+
+var cmdExportConfig = &cobra.Command{
+	Use:   "config",
+	Short: "Export the server configuration",
+	Long:  "Export the whole configuration as Kurzd sees it",
+	Run:   exportConfigHandler,
+}
+
+func init() {
+	cmdExport.AddCommand(cmdExportConfig)
+}
+
+func exportConfigHandler(cmd *cobra.Command, args []string) {
+	settings := viper.AllSettings()
+	y, err := yaml.Marshal(&settings)
+	if err != nil {
+		panic(err.Error())
+	}
+	fmt.Println(string(y))
+}

+ 3 - 3
cmd/kurzd/kurzd.go

@@ -13,8 +13,9 @@ import (
 
 /**
 kurzd
-	-v									Verbose (default: false).
-	help								Display help.
+	-h								Display top-level help
+	-v								Verbose (default: false).
+	help <command>					Display help (same as kurzd <command> -h)
 	server 							Serve kurz (default option).
 		-p|--port <port_id>			    Serve on this IP port (default: 80).
 		-m|--monitoring <port_id>         Serve monitoring on this IP port (default: none)
@@ -22,7 +23,6 @@ kurzd
 		config							Install the configuration define by command line to ~.
 		schema							Install the kurz database schema.
 	export							Export kurzd data.
-		-o <file>						Specify a destination file.
 		config						    Export kurz configuration.
 		content							Export kurz content.
 	uninstall						Uninstall kurzd completely.

+ 6 - 6
doc/use_cases/ops/ops1.md

@@ -6,13 +6,13 @@ As a system administrator
 In order to ensure system stability
 I need to access CPU, RAM, and storage metrics from kurzd
 
-As a system administrator for a system with SystemD
-In order to deploy Kurz
-I need to have a SystemD service for kurzd
+As a system administrator for a system without services 
+In order to install Kurz
+I need to have a one-step command to configure Kurz
 
-As a system administrator for a system without SystemD
-In order to deploy Kurz
-I need to have a SysV service for kurzd
+As a system administrator for a system without services 
+In order to uninstall Kurz
+I need to have a one-step command to ready Kurz for removal: database, configuration
 
 As a system administrator
 In order to guarantee traceability

+ 8 - 0
doc/use_cases/ops/ops2.md

@@ -1,3 +1,11 @@
+As a system administrator for a system with SystemD
+In order to install Kurz
+I need to have a SystemD service for kurzd
+
+As a system administrator for a system without System V services 
+In order to install Kurz
+I need to have a System V service for kurzd
+
 As a system administrator for an APT system
 In order to deploy Kurz
 I need to have Kurz available on an APT repository