Browse Source

Added support of new configuration to cppcms_run script

master
Artyom Beilis 15 years ago
parent
commit
78d56d0f49
3 changed files with 67 additions and 17 deletions
  1. +2
    -1
      Makefile.am
  2. +39
    -0
      cppcms_config_find_param.cpp
  3. +26
    -16
      cppcms_run

+ 2
- 1
Makefile.am View File

@@ -3,7 +3,7 @@
noinst_PROGRAMS = hello_world
#noinst_HEADERS = hello_world_view.h
#dist_bin_SCRIPTS = cppcms_tmpl_cc cppcms_run
#bin_PROGRAMS = cppcms_make_key
bin_PROGRAMS = cppcms_config_find_param # cppcms_make_key

#EXTRA_DIST = hello_world_skin1.tmpl hello_world_view1.tmpl hello_world_skin2.tmpl Changelog autogen.sh config.txt

@@ -51,6 +51,7 @@ libcppcms_la_SOURCES = \
json.cpp


cppcms_config_find_param_SOURCES=cppcms_config_find_param.cpp json.cpp


#libcppcms_la_SOURCES = global_config.cpp manager.cpp worker_thread.cpp \


+ 39
- 0
cppcms_config_find_param.cpp View File

@@ -0,0 +1,39 @@
#include "json.h"
#include <iostream>
#include <fstream>

int main(int argc,char **argv)
{
using namespace cppcms;
if(argc!=3)
return 1;
std::ifstream in(argv[2]);
if(!in)
return 1;
json::value v;
if(!v.load(in,true))
return 1;
std::string path=argv[1];
try {
std::cout<<v.get<double>(path);
return 0;
}
catch(json::bad_value_cast const &e) {}
try {
std::cout<<v.get<std::string>(path);
return 0;
}
catch(json::bad_value_cast const &e) {}
try {
std::vector<std::string> vs=v.get<std::vector<std::string> >(path);
std::string sep="";
for(unsigned i=0;i<vs.size();i++) {
std::cout<<sep<<vs[i];
sep=" ";
}
return 0;
}
catch(json::bad_value_cast const &e) {}
return 1;
}

+ 26
- 16
cppcms_run View File

@@ -301,7 +301,7 @@ if [ "$APACHE_MOD_DIR" == "" ] ; then
/usr/local/lib/httpd/modules \
/opt/lib/httpd/modules
do
if [ -f $p/mod_fastcgi.* ] ; then
if [ -f $p/mod_fastcgi.* ] || [ -f $p/mod_scgi.* ] ; then
APACHE_MOD_DIR="$p"
break;
fi
@@ -309,7 +309,7 @@ if [ "$APACHE_MOD_DIR" == "" ] ; then
fi
if [ "$APACHE_MOD_DIR" == "" ] ; then
if [ "$1" == "exit" ] ; then
echo "Can't find "mod_fastcgi" try specifing APACHE_MOD_DIR"
echo "Can't find "mod_fastcgi/mod_scgi" try specifing APACHE_MOD_DIR"
exit 1;
else
WEB_SERVER=""
@@ -317,9 +317,9 @@ if [ "$APACHE_MOD_DIR" == "" ] ; then
fi
fi

if [ "$API" != "fastcgi" ] ; then
if [ "$API" == "scgi" ] && [ "$SOCKET" != "" ]; then
if [ "$1" == "exit" ] ; then
echo "Apache2 supports fastcgi only"
echo "Apache2 supports scgi over tcp sockets only"
exit 1
else
WEB_SERVER=""
@@ -366,34 +366,44 @@ cat >$DIR/apache.conf << EOF
ErrorLog $DIR/apache.log

TypesConfig $DIR/mime.types
<VirtualHost *>
DocumentRoot $ROOT
</VirtualHost>

LoadModule alias_module $APACHE_MOD_DIR/mod_alias.so
LoadModule fastcgi_module $APACHE_MOD_DIR/mod_fastcgi.so
LoadModule mime_module $APACHE_MOD_DIR/mod_mime.so
EOF

if [ "$API" == "fastcgi" ];
then
cat >>$DIR/apache.conf <<EOF
LoadModule fastcgi_module $APACHE_MOD_DIR/mod_fastcgi.so

FastCgiIpcDir $DIR/ipc
FastCgiExternalServer $DIR/myapp.fcgi $SERVICE_POINT

ScriptAliasMatch ^$SCRIPT(.*)$ $DIR/myapp.fcgi\$1
AddHandler fastcgi-script .fcgi

<VirtualHost *>
DocumentRoot $ROOT
</VirtualHost>
EOF
else
cat >>$DIR/apache.conf <<EOF
LoadModule scgi_module $APACHE_MOD_DIR/mod_scgi.so
SCGIMount $SCRIPT $SERVICE_IP:$SERVICE_PORT
EOF

WEB_SERVER="$WEB_SERVER -f $DIR/apache.conf"
fi

}
WEB_SERVER="$WEB_SERVER -f $DIR/apache.conf"

find_numeric_param()
{
perl -e "while(<>) { print \"\$1\" if /^\s*$2\s*=\s*(\d+)\s*(#.*)?/}" <$1
}

find_param()
{
perl -e "while(<>) { print \"\$1\" if /^\s*$2\s*=\s*\"([^\"]+)\"\s*(#.*)?/}" <$1
if [ -e ./cppcms_config_find_param ]; then
./cppcms_config_find_param $2 $1
else
cppcms_config_find_param $2 $1
fi
}

help()
@@ -460,7 +470,7 @@ fi

SOCKET=`find_param $APP_CONFIG_FILE service.socket`
SERVICE_IP=`find_param $APP_CONFIG_FILE service.ip`
SERVICE_PORT=`find_numeric_param $APP_CONFIG_FILE service.port`
SERVICE_PORT=`find_param $APP_CONFIG_FILE service.port`
API=`find_param $APP_CONFIG_FILE service.api`

if [ "$API" == "" ] ; then


Loading…
Cancel
Save