Chapter 2
Core Configuration and Lifecycle Management
At the heart of any robust Yaws deployment lies precise configuration and agile process management. This chapter uncovers the articulated mechanisms and best practices that transform Yaws from a simple web server into a dependable, production-grade platform. Unlock the nuances of dynamic configuration, efficient lifecycle supervision, and strategies for operational resilience-empowering you to orchestrate Yaws in the most demanding environments.
2.1 Understanding Yaws Configuration Files
The Yaws web server configuration is primarily governed by the yaws.conf file, alongside other auxiliary configuration artifacts that collectively define server behavior, resource management, security policies, and module integration. These configuration elements are both syntactically straightforward and semantically rich, enabling fine-grained control over deployment contexts ranging from lightweight development setups to high-availability production environments.
At its core, the yaws.conf syntax embodies a hierarchical, key-value pair paradigm with sections demarcated by angular brackets. Each section, typically representing a virtual server or a global configuration scope, contains directives that specify parameters governing server processes, bindings, security settings, and module loading. The grammar is designed to be intuitive; for instance, a server binding block generally begins with <server> and is terminated by </server>, enclosing directives such as port, docroot, and ssl parameters.
<server localhost> port = 8080 docroot = /var/www/yaws ssl = false </server> The intentional modularity of Yaws configuration facilitates separation of concerns through the include directive. This directive supports both absolute and relative file paths, allowing administrators to distribute configuration fragments across multiple files. Employing include improves maintainability and reuse by enabling, for example, centralized SSL configuration files or user access rules to be shared between virtual servers. An example is:
include /etc/yaws/ssl.conf include conf/vhost_common.conf Advanced tuning of Yaws entails precise control over resource limits and operational parameters embedded within these configuration files. Resource limit directives such as maxclients govern the maximum simultaneous client connections, preventing system resource exhaustion. The directive max_keep_alive defines the maximum duration for persistent connections, critical for optimizing throughput while mitigating denial-of-service vectors. These tuning knobs impact runtime behavior directly and are specified within the appropriate server or global block.
Security configurations are significantly emphasized in Yaws, particularly with SSL/TLS setups. Within the server block, enabling SSL requires specifying parameters like ssl (boolean), ssl_certificate, ssl_key, and optionally ssl_ca_certificate for client validation. Here is a canonical SSL snippet illustrating these directives:
<server secure.domain.com> port = 443 ssl = true ssl_certificate = /etc/ssl/certs/server.pem ssl_key = /etc/ssl/private/server.key ssl_ca_certificate = /etc/ssl/certs/ca.pem </server> Binding directives are crucial for defining network interfaces and ports that Yaws listens on. While port is mandatory, the ip directive can be specified to bind to a particular network interface, allowing for multi-homed server setups. This enhances deployment versatility by enabling Yaws to serve distinct networks independently.
Modularization within Yaws configuration involves leveraging Erlang modules and extension points, which can be declared and loaded dynamically. The modules_dir directive points to a directory containing Erlang modules that can extend Yaws with custom request handlers or filters. Proper configuration is essential to correctly register and activate these modules, often involving additional directives within the server context to specify module and handler associations.
Change management of configuration files is a critical operational aspect for robust system administration. Manual edits risk introducing syntactical errors or risky settings that can incapacitate the server in production. To mitigate this, systematic automation of configuration validation is recommended. Basic syntax errors are caught by Yaws on startup; however, more comprehensive validation can be achieved through custom scripts or Erlang-based tools that parse and analyze the configuration semantics prior to deployment. For example, automated pipelines may integrate static analysis scripts that verify the existence and permissions of SSL files, cross-check IP bindings, and enforce organizational policies on resource limits.
Typical strategies for change management include maintaining configuration artifacts under version control systems such as Git, enabling traceable change histories and rollback capabilities. Coupled with continuous integration workflows, configuration changes can be automatically tested in staging environments before being deployed live. This process reduces configuration drift and enhances reliability.
In large-scale deployments, runtime reloading of configuration files without interrupting active connections is indispensable. Yaws provides mechanisms to gracefully reload or hot-swap configurations via Erlang node commands, permitting incremental updates with minimal...