Wednesday, October 1, 2014

Custom Server Configs - Linux

Keywords

Custom Config
Server Variables
System Based Configurations

CONFIG

custom environment variable to control IPs and and other custom variables between different servers.
    vi /etc/profile.d/custom.config.sh
this is the file that gets loaded into bash / system for custom configs. custom.config.sh example file
 export BROCK_READ_IP=192.168.0.118
 export BROCK_TEXT_IP=192.168.0.119
 export BROCK_WRITE_IP=192.168.0.100

 export FEEDP_IP=192.168.0.113
 export TECHDATA_IP=192.168.0.110
 export TECHSPECS_IP=10.30.0.155
 export DATALICENSE_IP=192.168.0.113
 export UPLOADER_IP=10.30.0.126
 export DATA1_IP=192.168.0.112

 export SERVER_TYPE=PRODUCTION
 export TASKS_USER=auto_tasks_dev

 export SEARCH_READ_DB_IP=192.168.0.119
 export SEARCH_WRITE_DB_IP=192.168.0.100
 export BROCK_JOOMLA_IP=192.168.0.100

BASH CRONTAB

    0 9 * * * cd /var/www/vhosts/techspecs/download; bash -l -c ./download.php

APACHE STARTUP

SERVICE RESTART INCLUDE ENVIRONMENT VARIABLES
vi /etc/sysconfig/httpd

add the following line at the end to automatically include the environment
variable shell script when httpd is started via a service call:

./etc/profile.d/custom.config.sh
ENVIRONMENT PASS THRU TO APACHE
vi /etc/httpd/conf/httpd.conf
OR
vi /etc/httpd/conf.d/virtual.host.name.conf

Use the following to add environment variables to the PassEnv

PassEnv TASKS_USER SERVER_TYPE ....
Example Usage
 # examples for PHP
 #  $_SERVER['DATALICENSE_IP']
 #  $_SERVER['BROKERB_IP']

 # examples for bash
 #  $DATALICENSE_IP
 #  $BROKERB_IP

This will allow you to have many VMs (virtual machines) with unique configurations without modifying your code base.  This is very useful for expansion of your network. Scalability is key.