github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/docs/configuration.md (about)

     1  ## Configuration
     2  
     3  In this section, we will describe how to configure Gohan server.
     4  
     5  Gohan server command takes "--config-file" parameter to specify
     6   configuration file.
     7  
     8  ```
     9    gohan server --config-file etc/gohan.yaml
    10  ```
    11  
    12  Note that there are some example configurations in the etc directory.
    13  Gohan server configuration uses YAML format.
    14  (For YAML specification, see http://yaml.org/)
    15  
    16  ```  #######################################################
    17    #  Gohan API Server example configuraion
    18    ######################################################
    19  
    20    include: gohan.d
    21    # database connection configuraion
    22    database:
    23        # sqlite3 and mysql supported
    24        type: "sqlite3"
    25        # connection string
    26        # it is file path for yaml, json and sqlite3 backend
    27        connection: "./etc/test.db"
    28        # please set no_init true in the production env, so that gohan don't initialize table
    29        # no_init: true
    30        initial_data:
    31            - type: "yaml"
    32              connection: "./etc/examples/heat_template.yaml"
    33    # schema path
    34    schemas:
    35      - "./etc/schema/gohan.json"
    36    # listen address for gohan
    37    address: ":9090"
    38    tls:
    39      enabled: true
    40      cert_file: "./etc/cert.pem"
    41      key_file: "./etc/key.pem"
    42    # document root of gohan API server
    43    # Note: only static and schema directoriy will be served
    44    document_root: "./etc"
    45    # list of etcd backend servers
    46    etcd:
    47        - "http://127.0.0.1:2379"
    48    # keystone configuraion
    49    keystone:
    50        use_keystone: false
    51        fake: true
    52        auth_url: "http://localhost:35357/v2.0"
    53        user_name: "admin"
    54        tenant_name: "admin"
    55        password: "gohan"
    56    # CORS (Cross-origin resource sharing (CORS)) configuraion for javascript based client
    57    cors: "*"
    58  
    59    # allowed levels  "CRITICAL", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG",
    60    logging:
    61        stderr:
    62            enabled: true
    63            level: DEBUG
    64        file:
    65            enabled: true
    66            level: INFO
    67            filename: ./gohan.log
    68  ```
    69  
    70  ## Include
    71  
    72  You can include config YAML files from specified dirs
    73  Note that overwrapped configuration will be overridden by configuration loaded later, so we don't recommend to have duplicated config file key in multiple files.
    74  
    75  ```
    76    include: gohan.d
    77  ```
    78  
    79  ## Environment Value
    80  
    81  
    82  You can use Environment value in the configuration.
    83  
    84  ```
    85    address: {{ .GOHAN_IP}}:{{ .GOHAN_PORT}}
    86  ```
    87  
    88  Note you need to use {{ and }}, and you need to put before
    89  your environment key.
    90  We are using Golang text template package, so please take a
    91  look more at https://golang.org/pkg/text/template/
    92  
    93  Database
    94  --------------------
    95  
    96  This section is for backend database configuration.
    97  You can select from sqlite3 and MySQL.
    98  
    99  a sample database configuraion for sqlite3.
   100  
   101  ```
   102    # database connection configuraion
   103    database:
   104        type: "sqlite3"
   105        connection: "./sqlite3.db"
   106  ```
   107  
   108  a sample database configuraion for sqlite3.
   109  
   110  ```
   111    # database connection configuraion
   112    database:
   113        type: "mysql"
   114        connection: "root:gohan@127.0.0.1/gohan"
   115  ```
   116  
   117  a sample database configuration for YAML backend.
   118  
   119  ```
   120    database:
   121        type: "yaml"
   122        connection: "./etc/example.yaml"
   123        initial_data:
   124            - type: "yaml"
   125              connection: "./etc/examples/initial_datayaml"
   126  ```
   127  
   128  Cascade deletion, i.e. creating FOREIGN KEYs with CASCADE ON DELETE,  can be activated with cascade switch.
   129  
   130  ```
   131    database:
   132        type: "mysql"
   133        connection: "root:gohan@127.0.0.1/gohan"
   134        cascade: true
   135  ```
   136  
   137  ## Schema
   138  
   139  Gohan works based on schema definitions.
   140  Developers should specify a list of schema file in the configuration.
   141  
   142  ```
   143  schemas:
   144      - "embed://etc/schema/gohan.json"
   145      - "embed://etc/extensions/gohan_extension.yaml"
   146      - "./example_schema.yaml"
   147  ```
   148  
   149  Developers can specify schemas here.
   150  Note that we always need gohan.json and gohan_extension.yaml for WebUI and CLI.
   151  
   152  ## Keystone
   153  
   154  Gohan supports OpenStack Keystone authentication backend.
   155  (see http://docs.openstack.org/developer/keystone/ )
   156  
   157  - use_keystone: boolean
   158  
   159    use keystone or not
   160  
   161  - fake: boolean
   162  
   163    use fake Keystone server for testing or not
   164  
   165  - auth_url
   166  
   167    keystone admin URL
   168  
   169  - user_name
   170  
   171    service username
   172  
   173  - tenant_name
   174  
   175    service tenant_name (needed for Keystone v2.0 API)
   176  
   177  - domain
   178  
   179    service domain name (needed for Keystone v3.0 API)
   180  
   181  - password
   182  
   183    password for a service user
   184  
   185  - version
   186  
   187    v2.0 or v3 is supported
   188  
   189  ```
   190    keystone:
   191        use_keystone: false
   192        fake: true
   193        auth_url: "http://localhost:35357/v2.0"
   194        user_name: "admin"
   195        tenant_name: "admin"
   196        password: "gohan"
   197  ```
   198  
   199  ## CORS
   200  
   201  Gohan supports Cross-Origin Resource Sharing (CORS) for supporting
   202  javascript WebUI without a proxy server.
   203  You need to specify allowed domain pattern in CORS parameter.
   204  Note: DO NOT USE * configuraion in production deployment.
   205  
   206  ```
   207    cors: "*"
   208  ```
   209  
   210  ## Logging
   211  
   212  You can define logging output in logging configuration.
   213  
   214  Developers can specify Logging level per log and per module in log. If a module is not specified in "modules",  a value from "level" is applied.
   215  
   216  Allowed log levels: "CRITICAL", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG",
   217  
   218  ```
   219    logging:
   220        stderr:
   221            enabled: true
   222            level: DEBUG
   223        file:
   224            enabled: true
   225            level: INFO
   226            modules:
   227                - name: gohan.db.sql
   228                  level: DEBUG
   229                - name: gohan.sync.etcd
   230                  level: CRITICAL
   231            filename: ./gohan.log
   232  ```
   233  
   234  ## HTTPS
   235  
   236  - enabled
   237  
   238    You can enable HTTPS support by setting this flag to ``true``.
   239    Disabling this option will cause Gohan to fallback to HTTP.
   240  
   241  - cert_file
   242  
   243    Location of X509 certificate file.
   244    e.g. ``"./etc/cert.pem"``
   245  
   246  - key_file
   247  
   248    Location of the key file is matching with a certificate.
   249    e.g. ``"./etc/key.pem"``
   250  
   251  ```
   252    tls:
   253      enabled: true
   254      cert_file: "./etc/cert.pem"
   255      key_file: "./etc/key.pem"
   256  ```
   257  
   258  ## Supported URL schemas
   259  
   260  URL schemes including file://, http://, https:// and embed:// are supported. file:// is default.
   261  For embed scheme, you can read embedded data in Gohan binary.
   262  Files stored under "etc/schema" and "etc/extensions".
   263  
   264  ## Extension
   265  
   266  - enable extension
   267  
   268  You can select extension types you use.
   269  
   270  ```
   271    extension:
   272      default: javascript
   273      use:
   274      - javascript
   275      - gohanscript
   276      - go
   277  ```
   278  
   279  - extension timelimit
   280  
   281    You can make timelimit for extension execution. Default is 30 sec
   282  
   283  ```
   284    extension:
   285      timelimit: 30
   286  ```
   287  
   288  - extension npm_path
   289  
   290    You can set npm_path for extensions. It should point to a directory of node_modules. The default is the current working directory.
   291  
   292  ```
   293    extension:
   294      npm_path: .
   295  ```
   296  
   297  ## Miscellaneous
   298  
   299  - address
   300  
   301    address to bind gohan sever.
   302    eg. 127.0.0.1:9090, 0.0.0.0:9090 or just :9090
   303  
   304  - document_root
   305  
   306    Clients such as WebUI needs gohan-meta-schema file. We will serve the file from configured document_root.
   307  
   308  - sync
   309  
   310    Sync type. The default is `etcd`, which means the etcd API version 2.
   311    `etcdv3` is available for etcd API version 3.
   312  
   313  - etcd
   314  
   315    list of etcd backend.
   316  
   317  ```
   318    etcd:
   319        - "http://192.0.0.1:2379"
   320        - "http://192.0.0.2:2379"
   321  ```
   322  
   323  - run job on an update from etcd
   324  
   325    You can run extension on update event on etcd using
   326    sync://{{etcd_path}}.
   327  
   328  a sample configuration.
   329  
   330  - watch/keys  list of watched keys in etcd. Gohan watches the path recursively.
   331  - events list of an event we invokes an extension
   332  - worker_count: number of concurrent execution tasks
   333  
   334  ```
   335    watch:
   336        keys:
   337          - v2.0
   338        events:
   339          - v2.0/servers/
   340        worker_count: 4
   341  ```
   342  
   343  WARNING: The value of watched etcd keys must be a JSON dictionary.
   344  
   345  - amqp
   346  
   347    You can listen to notification event from OpenStack components using
   348    AMQP. You need to specify listen to queues and events.
   349  
   350    You can also run extension for amqp based event specifying path for
   351    amqp://{{event_type}}.
   352  
   353  ```
   354    amqp:
   355        connection: amqp://guest:guest@172.16.25.130:5672/
   356        queues:
   357          - notifications.info
   358          - notifications.error
   359        events:
   360          - orchestration.stack
   361  ```
   362  
   363  - snmp
   364  
   365   You can listen to snmp trap, and execute extension for that trap.
   366   An extension path should be snmp://
   367  
   368  ```
   369    snmp:
   370      address: "localhost:8888"
   371  ```
   372  
   373  - cron
   374  
   375    You can periodically execute CRON job using configuration.
   376  
   377  ```
   378    cron:
   379        - path: cron://cron_job_sample
   380          timing: "*/5 * * * * *"
   381  ```
   382  
   383  - Job queue
   384  
   385    Gohan uses background job queue & workers.
   386    You can decide how many worker can run concurrently.
   387  
   388  ```
   389     workers: 100
   390  ```
   391  
   392  - schema editor
   393  
   394    You can use a Gohan server as a schema editor if you specify editable_schema YAML file.
   395    Gohan updates this file based on schema REST API call.
   396  
   397  
   398  ```
   399     editable_schema: ./example_schema.yaml
   400  ```
   401  
   402  ## Graceful Shutdown and Restart
   403  
   404  Gohan supports graceful shutdown and restart.
   405  
   406  For a graceful shutdown, send SIGTERM for Gohan process.
   407  For graceful restart, you need to use server-starter utility.
   408  
   409  ```
   410    gohan glace-server --config-file etc/gohan.yaml
   411  ```
   412  
   413  or you can use start_server utility
   414  
   415  ```
   416    # Installation
   417    go get github.com/lestrrat/go-server-starter/cmd/start_server
   418    # Run gohan server with start_server utility
   419    start_server --port 9091 -- gohan server --config-file etc/gohan.yaml
   420  ```