head	1.30;
access;
symbols
	caudium_1_2_35:1.12.2.3
	caudium_1_2_34:1.12.2.3
	caudium_1_2_33:1.12.2.3
	caudium_1_2_32:1.12.2.3
	caudium_1_3_21:1.27
	caudium_1_3_20:1.27
	caudium_1_3_19:1.25
	caudium_1_3_18:1.25
	caudium_1_2_31:1.12.2.1
	caudium_1_2_30:1.12.2.1
	caudium_1_2_29:1.12.2.1
	caudium_1_2_28:1.12.2.1
	caudium_1_3_17:1.25
	caudium_1_3_16:1.25
	caudium_1_2_27:1.12.2.1
	caudium_1_2_26:1.12.2.1
	caudium_1_2_25:1.12.2.1
	caudium_1_2_24:1.12.2.1
	caudium_1_0_57:1.10.4.2
	caudium_1_0_56:1.10.4.2
	caudium_1_3_15:1.22
	caudium_1_3_14:1.22
	caudium_1_2_23:1.12.2.1
	caudium_1_2_22:1.12.2.1
	caudium_1_2_21:1.12.2.1
	caudium_1_2_20:1.12.2.1
	caudium_1_0_55:1.10.4.2
	caudium_1_0_54:1.10.4.2
	caudium_1_3_13:1.20
	caudium_1_3_12:1.20
	caudium_1_3_11:1.18
	caudium_1_3_10:1.18
	caudium_1_2_19:1.12.2.1
	caudium_1_2_18:1.12.2.1
	caudium_1_3_9:1.18
	caudium_1_3_8:1.18
	caudium_1_3_7:1.16
	caudium_1_3_6:1.16
	caudium_1_2_17:1.12.2.1
	caudium_1_2_16:1.12.2.1
	caudium_1_2_15:1.12.2.1
	caudium_1_2_14:1.12.2.1
	caudium_1_2_12:1.12.2.1
	caudium_1_2_10:1.12.2.1
	caudium_1_3_5:1.16
	caudium_1_3_4:1.16
	caudium_1_2_9:1.12.2.1
	caudium_1_2_8:1.12.2.1
	caudium_1_3_3:1.13
	caudium_1_2_7:1.12.2.1
	caudium_1_2_6:1.12.2.1
	caudium_1_0_53:1.10.4.2
	caudium_1_0_52:1.10.4.2
	caudium_1_0_51:1.10.4.2
	caudium_1_0_50:1.10.4.2
	caudium_1_0_45:1.10.4.2
	caudium_1_0_44:1.10.4.2
	caudium_1_0_43:1.10.4.2
	caudium_1_0_42:1.10.4.2
	Caudium_1_3_2:1.13
	caudium_1_2_5:1.12
	caudium_1_2_4:1.12
	caudium_1_0_41:1.10.4.2
	caudium_1_0_40:1.10.4.2
	caudium_1_0_39:1.10.4.2
	Caudium_1_0_38:1.10.4.2
	caudium_1_2_3:1.12
	caudium_1_2_2:1.12
	caudium_1_3_1:1.12
	caudium_1_2_1:1.12
	stable_1_2:1.12.0.2
	caudium_1_0_37:1.10.4.2
	caudium_1_0_36:1.10.4.2
	caudium_1_1_5:1.12
	caudium_1_1_4:1.12
	caudium_1_1_3:1.12
	caudium_1_1_2:1.12
	caudium_1_0_34:1.10.4.2
	caudium_1_0_32:1.10.4.2
	caudium_1_0_30:1.10.4.2
	caudium_1_0_28:1.10.4.2
	caudium_1_0_24:1.10.4.2
	caudium_1_0_22:1.10.4.1
	caudium_1_0_20:1.10.4.1
	caudium_1_0_18:1.10.4.1
	caudium_1_0_17:1.10.4.1
	caudium_1_0_16:1.10.4.1
	caudium_1_0_15:1.10.4.1
	caudium_1_0_14:1.10.4.1
	caudium_1_0_13:1.10.4.1
	caudium_1_0_12:1.10.4.1
	caudium_1_0_11:1.10.4.1
	caudium_1_0_10:1.10.4.1
	stable_1_0:1.10.0.4
	caudium_1_0_9:1.10
	caudium_1_0_8:1.10
	caudium_1_0_7:1.10
	caudium_1_0_6:1.10
	caudium_1_0_5:1.9
	caudium_1_0_4:1.9
	caudium_1_0_3:1.9
	caudium_1_0_2:1.9
	start:1.1.1.1
	Roxen:1.1.1;
locks; strict;
comment	@# @;


1.30
date	2003.11.03.15.05.59;	author hww3;	state dead;
branches;
next	1.29;

1.29
date	2003.10.20.18.13.35;	author hww3;	state Exp;
branches;
next	1.28;

1.28
date	2003.10.20.18.11.29;	author hww3;	state dead;
branches;
next	1.27;

1.27
date	2003.08.30.23.28.04;	author hww3;	state Exp;
branches;
next	1.26;

1.26
date	2003.07.16.12.58.19;	author vida;	state Exp;
branches;
next	1.25;

1.25
date	2003.02.27.10.11.35;	author jnt;	state Exp;
branches;
next	1.24;

1.24
date	2003.02.17.23.19.23;	author grendel;	state Exp;
branches;
next	1.23;

1.23
date	2003.02.17.23.17.51;	author grendel;	state Exp;
branches;
next	1.22;

1.22
date	2003.02.05.21.55.31;	author hww3;	state Exp;
branches;
next	1.21;

1.21
date	2003.02.05.18.43.46;	author hww3;	state Exp;
branches;
next	1.20;

1.20
date	2002.12.06.15.23.54;	author kiwi;	state Exp;
branches;
next	1.19;

1.19
date	2002.12.06.15.05.07;	author kiwi;	state Exp;
branches;
next	1.18;

1.18
date	2002.11.20.19.27.23;	author vida;	state Exp;
branches;
next	1.17;

1.17
date	2002.11.20.19.19.02;	author vida;	state Exp;
branches;
next	1.16;

1.16
date	2002.08.30.01.47.05;	author hww3;	state Exp;
branches;
next	1.15;

1.15
date	2002.06.20.16.23.22;	author kazmer;	state Exp;
branches;
next	1.14;

1.14
date	2002.06.19.17.57.58;	author kiwi;	state Exp;
branches;
next	1.13;

1.13
date	2002.05.03.15.54.26;	author grendel;	state Exp;
branches;
next	1.12;

1.12
date	2001.05.31.18.21.14;	author neotron;	state Exp;
branches
	1.12.2.1;
next	1.11;

1.11
date	2001.02.13.20.46.35;	author neotron;	state Exp;
branches;
next	1.10;

1.10
date	2000.11.19.04.21.13;	author kiwi;	state Exp;
branches
	1.10.4.1;
next	1.9;

1.9
date	2000.09.25.19.11.45;	author neotron;	state Exp;
branches;
next	1.8;

1.8
date	2000.09.11.23.46.05;	author neotron;	state Exp;
branches;
next	1.7;

1.7
date	2000.08.13.07.40.53;	author embee;	state Exp;
branches;
next	1.6;

1.6
date	2000.08.12.08.36.33;	author neotron;	state Exp;
branches;
next	1.5;

1.5
date	2000.08.09.21.24.50;	author neotron;	state Exp;
branches;
next	1.4;

1.4
date	2000.08.07.04.05.49;	author neotron;	state Exp;
branches;
next	1.3;

1.3
date	2000.08.07.00.50.42;	author neotron;	state Exp;
branches;
next	1.2;

1.2
date	2000.08.04.01.42.41;	author neotron;	state Exp;
branches;
next	1.1;

1.1
date	2000.07.28.16.31.07;	author neotron;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.07.28.16.31.07;	author neotron;	state Exp;
branches;
next	;

1.10.4.1
date	2000.12.13.06.14.14;	author neotron;	state Exp;
branches;
next	1.10.4.2;

1.10.4.2
date	2001.02.13.20.43.55;	author neotron;	state Exp;
branches;
next	;

1.12.2.1
date	2002.05.03.16.26.25;	author grendel;	state Exp;
branches;
next	1.12.2.2;

1.12.2.2
date	2004.01.20.21.47.30;	author bertrand;	state Exp;
branches;
next	1.12.2.3;

1.12.2.3
date	2004.01.21.16.16.49;	author bertrand;	state Exp;
branches;
next	;


desc
@@


1.30
log
@removing old files.
@
text
@#!@@PIKEBIN@@
/*
 * Caudium - An extensible World Wide Web server
 * Copyright  2003-2000 The Caudium Group
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
 
/*
 * Authors: 
 *   Marek Habersack <grendel@@caudium.net>
 *   Bill Welliver <hww3@@riverweb.com>
 *
 * License: MPL/LGPL
 * 
 * $Id: start,v 1.29 2003/10/20 18:13:35 hww3 Exp $
 */
 
// for convenience
string pikever = sprintf("%u.%u.%u/", __REAL_MAJOR__, __REAL_MINOR__, __REAL_BUILD__);

// arguments we understand
array(array(string | array(string))) arguments = ({
  ({"quiet", Getopt.NO_ARG, ({"--quiet"})}),
  ({"truss", Getopt.NO_ARG, ({"--truss"})}),
  ({"strace", Getopt.NO_ARG, ({"--strace"})}),
  ({"ltrace", Getopt.NO_ARG, ({"--ltrace"})}),
  ({"log-dir", Getopt.HAS_ARG, ({"--log-dir", "--logdir"})}),
  ({"config-dir", Getopt.HAS_ARG, ({"--config-dir", "--configdir"})}),
  ({"pike-version", Getopt.HAS_ARG, ({"--pike-version", "--pikeversion"})}),
  ({"pid-file", Getopt.HAS_ARG, ({"--pid-file", "--pidfile"})}),
  ({"debug", Getopt.NO_ARG, ({"--debug", "--with-debug", "--enable-debug"})}),
  ({"watchdog", Getopt.NO_ARG, ({"--with-watchdog", "--watchdog", "--enable-watchdog"})}),
  ({"nowatchdog", Getopt.NO_ARG, ({"--without-watchdog", "--nowatchdog", "--disable-watchdog"})}),
  ({"nodebug", Getopt.NO_ARG, ({"--without-debug", "--nodebug", "--disable-debug"})}),
  ({"fddebug", Getopt.NO_ARG, ({"--fd-debug", "--with-fd-debug", "--enable-fd-debug"})}),
  ({"threads", Getopt.NO_ARG, ({"--threads", "--with-threads", "--enable-threads"})}),
  ({"nothreads", Getopt.NO_ARG, ({"--no-threads", "--without-threads", "--disable-threads"})}),
  ({"profile", Getopt.NO_ARG, ({"--profile", "--with-profile", "--enable-profile"})}),
  ({"fileprofile", Getopt.NO_ARG, ({"--file-profile", "--with-file-profile", "--enable-file-profile"})}),
  ({"keepalive", Getopt.NO_ARG, ({"--keep-alive", "--with-keep-alive", "--enable-keep-alive"})}),
  ({"pike", Getopt.HAS_ARG, ({"--with-pike"})}),
  ({"once", Getopt.NO_ARG, ({"--once"})}),
  ({"gdb", Getopt.MAY_HAVE_ARG, ({"--gdb"}), 0, "gdb"}),
  ({"program", Getopt.HAS_ARG, ({"--program"})}),
  ({"version", Getopt.NO_ARG, ({"--version"})}),
  ({"backgrounded", Getopt.NO_ARG, ({"--backgrounded"})}),
  ({"help", Getopt.NO_ARG, ({"--help", "-?"})})
});

// loader options (with defaults)
mapping(string:mixed) options = ([
  "gdb" : "gdb",
  "pike" : 0,
  "pikever" : 0,
  "threads" : 1,
  "program" : "base_server/caudiumloader.pike", 
]);


// environment variables we set for caudium
// all of them are merged with the values of variables from the shell
// environment, if they exist. The existing variables are appended to the
// values below. Some of the variables are constructed dynamically, those
// are not included in the mapping below.
mapping(string:string|array) envvars = ([
  "CAUDIUM_CONFIGDIR" : getenv("CAUDIUM_CONFIGDIR") || "../configurations",
  "CAUDIUM_LOGDIR" : getenv("CAUDIUM_LOGDIR") || "../logs",
  "CAUDIUM_PID_FILE" : getenv("CAUDIUM_PID_FILE") || ("/tmp/caudium_" + getenv("UID")),
  "CLASSPATH" : getenv("CLASSPATH") +":" + 
     ("etc/classes:etc/classes/caudium_search.jar:etc/classes/lucene_1.2.jar:"
      "etc/classes/caudium_servlet.jar:etc/classes/jsdk.jar"),
  "PIKE_MODULE_PATH" : getenv("PIKE_MODULE_PATH") || "",
  "CAUDIUM_LANG" : getenv("CAUDIUM_LANG") || "en"
]);

// locations that we should search for modules in, if present
array lib_locations=({"lib/modules", 
  "lib/pike/modules", "etc/modules", "lib/" + pikever,
  "share/pike/modules"});
      
// locations that we should search for programs in, if present
array program_locations=({getcwd()});
      
// locations that we should search for includes in, if present
array include_locations=({"lib/include", "etc/include", 
  "share/pike/include", "base_server"});

// parsed arguments
array parsed_args=({});

// so we can spawn ourselves.
array passed_args=({});
mapping passed_env=getenv();

// The webserver process
Process.Process   proc;

// components of the Caudium command line.
mapping(string:string|array) command_line = ([
  "DEFINES" : ({}),
  "INCLUDES" : ({}),
  "PROGRAMS" : ({}),
  "COTHER": ({})
]);

// a list of valid interpreters we should try to use.
array valid_interpreters=({"bin/caudium", "bin/pike"});

// run Caudium and return its exit status.
int run_caudium(array(string) args, mapping|void opts)
{
  mapping           myopts = opts || ([]);

  opts->cwd = getcwd();
  opts->env = getenv() | envvars;
//  write("args: %O opts: %O", args, opts);
  if(!options->quiet)
  {
    write("Starting the Caudium Webserver.\n"
        "Log dir is " + envvars->CAUDIUM_LOGDIR + ", Configuration dir is " + envvars->CAUDIUM_CONFIGDIR 
        + "\n");
    if(!options->once)
        write("Debug output is located in " + envvars->CAUDIUM_LOGDIR + "/debug/default.1\n");
  }
  if(opts->stdout && !options->quiet)
    opts->stdout->write("Running " + (args*" ") + "\n");
//  args=({"/bin/sleep", "60"});
  proc = Process.create_process(args, opts);

  if (!proc) {
    if(opts->stderr)
      opts->stderr->write("Failed to execute the child process\n");
    else werror("Failed to execute the child process\n");
    return 1;
  }

  return 1;

//  return proc->wait();
}

void append_env_path(string envvar, string value)
{
  if (!envvar || !sizeof(envvar))
    return;
  
  if (envvars[envvar] && sizeof(envvars[envvar]))
    envvars[envvar] += ":";
  envvars[envvar] += value;
}

// Sets some initial and extra values. This function MUST be ran with the
// cwd set to the caudium toplevel directory.
void preamble()
{
  mapping(string:string)  osdata = System.uname();
  int                     go_threads = 0;
  string                  os_label = "";
  array(string)           os_rel;
  Stdio.Stat              fstat;

  if (options->pikever) {
    fstat = file_stat("bin/caudium-" + options->pikever);
    if (fstat && fstat->isreg && (fstat->mode & 0111))
      options->pike = "bin/caudium-" + options->pikever;
    if (!options->pike) {
      fstat = file_stat("bin/pike-" + options->pikever);
      if (fstat && fstat->isreg && (fstat->mode & 0111))
        options->pike = "bin/pike-" + options->pikever;
    }
    if (!options->pike) {
      write("Cannot find Pike v%s in %s/bin/\n", options->pikever, getcwd());
      exit(1);
    }
  }

  // we're not specifying a pike version to use internally
  else {
    if(options->pike)
    {
      fstat=file_stat(options->pike);
      if(!(fstat && fstat->isreg && (fstat->mode & 0111)))
      {
        write("Specificed Pike %s does not exist or is not executable.\n", options->pike);
        exit(1);
      }
    }
    else
    {
      foreach(valid_interpreters, string vi)
      {
        fstat=file_stat(vi);
        if (fstat && fstat->isreg && (fstat->mode & 0111))
        {
          options->pike = vi;
          break;
        }
      }
    if(!options->pike || options->pike=="")
    {
      write("Unable to find a usable Pike interpreter.\n");
      exit(1);
    }

    }
  }

  os_rel = osdata->release / ".";
  if (sizeof(os_rel) < 2)
    os_rel += ({"0"}); // better this than nothing
  
  switch(osdata->sysname) {
      case "SunOS":
        if ((int)os_rel[0] >= 5 && (int)os_rel[1] >= 5) {
          os_label = "Solaris 2.5 or later";
          go_threads = 1;
        }
        break;

      case "FreeBSD":
        if ((int)os_rel[0] >= 4) {
          os_label = "FreeBSD 4.0 or later";
          go_threads = 1;
        }
        break;

      case "Linux":
        if ((int)os_rel[0] >= 2 && (int)os_rel[1] >= 2) {
          os_label = "Linux 2.2 or later";
          go_threads = 1;
        }
        break;

      case "Darwin":
        os_label = "Darwin or MacOS X";
        go_threads = 1;
        break;
  }

  if (go_threads && options->threads) {
    if(!options->quiet && !options->backgrounded)
      write("%s detected, enabling threads (if available in Pike)\n",
          os_label);
    command_line->DEFINES += ({"ENABLE_THREADS"});
  }

  command_line->DEFINES += ({"CAUDIUM", "CAUDIUM_CACHE", "ROXEN"});

  System.umask(022);

  if (!getenv("PIKE_NO_DEFAULT_PATHS")) {
    if (!getenv("PIKE_MASTER")) { // Pike default master program

      command_line->OTHER += ({"-w"});
/*
      foreach(master_locations, string ml)
      {
         if(Stdio.is_file(ml))
         {
           command_line->OTHER += ({"-m" + ml});
         }
      }
*/
      foreach(include_locations, string il)
      {
         if(Stdio.is_dir(il))
         {
           command_line->INCLUDES += ({il});
           add_include_path(il);
         }
      }

      foreach(lib_locations, string ll)
      {
         if(Stdio.is_dir(ll))
         {
           command_line->MODULES += ({ll});
           add_module_path(ll);
         }
       }

      foreach(program_locations, string pl)
      {
         if(Stdio.is_dir(pl))
         {
           command_line->PROGRAMS += ({pl});
           add_program_path(pl);
         }
      }
   }
   else {
      command_line->OTHER += ({"-m" + getenv("PIKE_MASTER")});
    }
  }

  // a kludge for HPUX which doesn't like group 60001 (nobody)
  if (osdata->sysname == "HP-UX") {
    if(!options->quiet)
      write("WARNING: applying a kludge for HPUX (see base_server/privs.pike)\n");
    command_line->DEFINES += ({"HPUX_KLUDGE"});
  }
}

array parse_arguments(array(string) argv)
{
  array(array)  parsed = Getopt.find_all_options(argv, arguments, 0);
  argv-=({0});
  if(sizeof(argv)>1) command_line->PROG_OTHER += argv[1..];
  return parsed;
}

string dirname(string p)
{
  array x=p/"/";
  if(sizeof(x)<2) return 0;
  x=x[0..(sizeof(x)-2)];
  p=x*"/";
  return p;
}

int main(int argc, array(string) argv)
{
  // first, copy argv to a safe place.
  passed_args=copy_value(argv);
// write("%O\n", passed_args);
  // next, change into the directory that start is living in.
  string d=dirname(argv[0]);
  if(d) cd(d);

  // is the directory we're in a valid caudium server root?
  if(!file_stat("base_server")) 
  {
    write("Cannot find Caudium server root\n");
    exit(1);
  }       

  parsed_args=parse_arguments(argv);

  int code=act_on_args();

  // do we get a "quit" code from the arg handler?
  if(code) return 0;

  preamble();
  if(!options->once && !options->backgrounded)
  {
    Process.create_process(passed_args + ({"--backgrounded"}), (["env": passed_env]));
    sleep(1);
    return 0;
  }
  write("options: %O\n", options);

  // set up signal handlers
  setup_signals();

  call_out(continue_startup, 0);
  return -1;
  
}

void setup_signals()
{
  signal(signum("SIGHUP"), signal_hup);
  signal(signum("SIGINT"), signal_int);
  signal(signum("SIGTERM"), signal_term);
}

// we pass HUP on to Caudium
void signal_hup()
{
  write("Sending HUP to Caudium (to force reload of configurations.)\n");
  if(proc && proc->status()==0)
  {
    proc->kill(signum("SIGHUP"));
  }
}

// we stop caudium and the start process
void signal_term()
{
  if(proc && proc->status()==0)
  {
    write("Sending shutdown request to Caudium.\n");
    proc->kill(signum("SIGTERM"));
  }
  exit(0);
}

// we stop caudium and restart it
void signal_int()
{
  write("Restarting Caudium.\n");
  if(proc && proc->status()==0)
  {
    proc->kill(signum("SIGINT"));
  }
}

void continue_startup()
{
  array o = generate_command_options();

    mapping opt=([]);

  if(options->once)
  {
    opt->stdout = Stdio.File("stdout");
    opt->stderr = Stdio.File("stderr");

    if(options->precmd && options->precmd[0]=="gdb")
    {
       Stdio.write_file(".gdbinit", "handle SIGPIPE nostop noprint pass\n"
        "handle SIGUSR1 nostop noprint pass\n"
        "handle SIGUSR2 nostop noprint pass\n"
        "run " + (o*" ") + "\n");
       do_one_run(options->precmd + ({options->pike}), opt);
    }

    else do_one_run(o, opt);

  }

  else // we're backgrounded, and we should start caudium now.
  {
    do_multi_run(o, opt);
  }
  return 0;
}

void do_one_run(array o, mapping opt)
{
    call_out(do_one_run, 2, o, opt);
    // if we don't have a running process, exit.
    if(!proc)
    {
       run_caudium(o, opt);
    }
    else if(proc->status()!=0)
    {
      if(options->precmd[0]=="gdb")
        rm(".gdbinit");
    }


}

void do_multi_run(array o, mapping opt)
{
    call_out(do_multi_run, 2, o, opt);
    // if we don't have a running process, start it.
    if(!proc || proc->status()!=0)
    {
      rotate_logs(o, opt);
      opt->stdout=Stdio.File(envvars->CAUDIUM_LOGDIR + "/debug/default.1", "crw");
      opt->stderr=opt->stdout;
      opt->setsid=1;
      run_caudium(o, opt);
    }


}

void rotate_logs(array o, mapping opt)
{
  for(int i=8; i>0; i--)
  {
    mv(envvars->CAUDIUM_LOGDIR + "/debug/default." + i, envvars->CAUDIUM_LOGDIR + "/debug/default." + (i+1));
  }
}

array generate_command_options()
{
  array o=({});

  if(!options->precmd ||  options->precmd[0]!="gdb")
  {
    if(options->precmd)
      o+=options->precmd;
    o+=({options->pike});
  } 

    if(command_line->DEFINES)
      foreach(command_line->DEFINES, string d)
        o+=({"-D" + d});
    if(command_line->INCLUDES)
      foreach(command_line->INCLUDES, string d)
        o+=({"-I" + d});
    if(command_line->MODULES)
      foreach(command_line->MODULES, string d)
        o+=({"-M" + d});
    if(command_line->PROGRAMS)
      foreach(command_line->PROGRAMS, string d)
        o+=({"-P" + d});
    if(command_line->OTHER)
      foreach(command_line->OTHER, string d)
        o+=({d});

    o+=({options->program});

    if(command_line->PROG_OTHER)
      foreach(command_line->PROG_OTHER, string d)
        o+=({d});

  return o;
} 

int act_on_args()
{
  foreach(parsed_args, array m)
  {
    switch(m[0])
    {
      case "truss":
        options->precmd=({"truss"});
        options->once=1;
        continue;
      case "strace":
        options->precmd=({"strace", "-f"});
        options->once=1;
        continue;
      case "ltrace":
        options->precmd=({"ltrace", "-f"});
        options->once=1;
        continue;
      case "log-dir":
        envvars->CAUDIUM_LOGDIR=m[1];        
        continue;
      case "config-dir":
        envvars->CAUDIUM_CONFIGDIR=m[1];        
        continue;
      case "pike-version":
        options->pikever=m[1];
        continue;
      case "pid-file":
        envvars->CAUDIUM_PID_FILE=m[1];
        continue;
      case "backgrounded":
        options->backgrounded=1;
        continue;
      case "help":
        write_help();
        return 1;
        continue;
      case "threads":
        options->threads=1;
        continue;
      case "nothreads":
        options->threads=0;
        continue;
      case "profile":
         command_line->DEFINES+=({"PROFILE"});
         continue;
      case "fileprofile":
         command_line->DEFINES+=({"FILE_PROFILE"});
         continue;
      case "once":
         options->once=1;
         continue;
      case "gdb":
         options->precmd=({"gdb"});
         options->once=1;
         continue;
      case "nodebug":
         command_line->DEFINES-=({"DEBUG", "MODULE_DEBUG", "CACHE_DEBUG"});
         continue;
      case "debug":
         command_line->DEFINES+=({"DEBUG", "MODULE_DEBUG", "CACHE_DEBUG"});
         continue;
      case "fddebug":
         command_line->DEFINES+=({"FD_DEBUG"});
         continue;
      case "keepalive":
        command_line->DEFINES+=({"KEEP_ALIVE"});
        continue;
      case "version":
         command_line->COTHER+=({"--version"});
         options->once=1;
         continue;
      case "pike":
        options->pike=m[1];
        continue;
      case "program":
        options->program=m[1];
        options->once=1;
        continue;
      case "quiet":
        options->quiet=1;
        continue;
    }
  return 0;
  }
}

void write_help()
{
   object ti=Stdio.Terminfo.getTerm();
   string bon=ti->tgetstr("md");
   string boff=ti->tgetstr("me");

   write( replace(
# ".BThis command will start the Caudium serverB..
The environment variable .BCAUDIUM_ARGSB. can be used to specify the
default arguments.
   .BArguments:B.
      .B--versionB.:  Output version information.
      .B--help -?B.:  This information
      .B--pike-version=VERB.:  Use an alternate pike version. For this to
				  work correctly, you need a
bin/caudium-VER
				  and the Caudium pike modules in
lib/VER/.
      .B--log-dir=DIRB.:  Set the log directory. Defaults to .B../logsB..
      .B--config-dir=DIRB.:  Use an alternate configuration directory
				  Defaults to .B../configurationB..
      .B--with-threadsB.:  If threads are available, use them.
      .B--without-threadsB.:  Even if threads are enabled by default,
                                  disable them.
      .B--with-profileB.:  Store runtime profiling information on
				  a directory basis. This information is
 				  not saved on permanent storage, it is
only
				  available until the next server restart
				  This will enable a new 'action' in the
				  configuration interface
      .B--with-file-profileB.:  Like .B--with-profileB., but save
information
                                  for each and every file.
      .B--with-keep-aliveB.:  Enable keep alive in the HTTP
			          protocol module. This will soon be
                                  the default. Some clients might have
				  problems with keepalive.
				  
      .B--onceB.:  Run the server only once, in the foreground.
			   	  This is very useful when debugging.
      .B--gdbB.:  Run the server in gdb. Implies .B--onceB..
      .B--programB.:  Start a different program with the caudium pike. As
an example,
                                  .B./start --program bin/install.pikeB.  
will
				  start the installation program normally
                                  started with .B./installB. Implies --once.
      .B--quietB.:  Run without normal debug output from the
                                  start script. Useful mainly when starting
				  other programs with --program.

      .B--with-watchdogB.:  Enable watchdog (default)
      .B--without-watchdogB.:  Disable watchdog

      .B--with-debugB.:  Enable debug
      .B--without-debugB.:  Disable all debug
	
      .B--with-fd-debugB.:  Enable FD debug.
      .B--truss,--strace,--ltraceB.: Run the server under the selected tracer
                   		  program. This is extremely noisy, and is not
				  intented for anything but debugging purposes.
      .B--pid-file=<file>B.:  Store the caudium and startscript pids in this
				  file. Defaults to .B/tmp/caudium_\$UIDB.
         
  .BArguments passed to pike:B.
       .B-DDEFINEB.:  Define the symbol .BDEFINEB..
       .B-d<level>B.:  Set the runtime pike debug to level.
				  This only works if pike is compiled
				  with debug.
       .B-s<size>B.:  Set the stack size.
       .B-M <path>B.:  Add the path to the pike module path.
       .B-I <path>B.:  Add the path to the pike include path.
       .B-dtB.:  Turn of tail recursion optimization.
       .B-tB.:  Turn on pike level tracing.
       .B-t<level>B.:  Turn on more pike tracing. This only
				  works if pike is compiled with debug.
  .BEnvironment variables:B.
     .BCAUDIUM_CONFIGDIRB.:  Same as .B--config-dir=... B.
     .BCAUDIUM_PID_FILEB.:  Same as .B--pid-file=... B.
     .BCAUDIUM_LANGB.:  The default language for all language
				    related tags. Defaults to 'en' for english.

  .BProcess Control:B.
     Sending TERM to the start process will shutdown the starter and caudium (if it's able to exit on its own)
     Sending HUP to the start process will cause caudium to reload its configurations
     Sending INT to the start process will cause caudium to restart itself (if it's able to do this on its own)
", ({".B", "B."}), ({bon, boff}))
);

}
@


1.29
log
@enter pike
@
text
@d29 1
a29 1
 * $Id: start,v 1.2 2003/10/16 22:46:55 hww3 Exp $
@


1.28
log
@making way for pikey goodness
@
text
@d1 149
a149 205
#!/bin/sh
#
# $Id: start,v 1.27 2003/08/30 23:28:04 hww3 Exp $

# Can be set with '--config-dir=DIR'
DIR=../configurations/
LOGDIR=../logs/
FILES="default"
program=base_server/caudiumloader.pike
program_echo="Starting the Caudium World Wide Web server."

# Set up environment
if test -f etc/environment; then
  . etc/environment
fi

# All Caudium launcher script, core and modules make the rely on getcwd() 
# being Caudium base path
cd `pwd`; cd `dirname $0`

# Make sure $CLASSPATH contains the servlet stuff
CLASSPATH=etc/classes/caudium_search.jar:etc/classes/lucene-1.2.jar:etc/classes:etc/classes/caudium_module.jar:etc/classes/caudium_servlet.jar:etc/classes/servlet.jar:etc/classes/servlet.jar:etc/classes/jsdk.jar${CLASSPATH:+:}$CLASSPATH
export CLASSPATH

# Try to enable threads on Solaris (2.5+), FreeBSD (4.0+) and Linux (2.2+)
OSTYPE=`uname -s`
OSMAJOR=`uname -r | sed 's/\..*$//'`
OSMINOR=`uname -r | sed 's/^[^\.]\.//;s/[\.-].*$//'`
if [ "$OSTYPE" = "SunOS" -a "$OSMAJOR" -ge 5 -a "$OSMINOR" -ge 5 ]; then
  echo "Solaris 2.5 or later detected, enabling threads if available."
  DEFINES="$DEFINES -DENABLE_THREADS"
elif [ "$OSTYPE" = "FreeBSD" -a "$OSMAJOR" -ge 4 ]; then
  echo "FreeBSD 4.0 or later detected, enabling threads if available."
  DEFINES="$DEFINES -DENABLE_THREADS"
elif [ "$OSTYPE" = "Linux" -a "$OSMAJOR" -ge 2 -a "$OSMINOR" -ge 2 ]; then
  echo "Linux 2.2 or later detected, enabling threads if available."
  DEFINES="$DEFINES -DENABLE_THREADS"
elif [ "$OSTYPE" = "Darwin" ]; then
  echo "Darwin or Mac OS X detected, enabling threads if available."
  DEFINES="$DEFINES -DENABLE_THREADS"
fi

# Caudium will create files as the initial user,
# which it expects to be able to read as the run-time user.
umask 022

if [ "x$PIKE_NO_DEFAULT_PATHS" = "x" ]; then
  # Pike default Master-program
  if [ "x$PIKE_MASTER" = "x" ]; then
    if [ -d share/pike ]; then
      # This is used with localinstall
      DEFINES="$DEFINES -Ishare/pike/include"
      PIKE_MODULE_PATH="$PIKE_MODULE_PATH:share/pike/modules"
    fi
    if [ -f lib/master.pike ]; then
      DEFINES="$DEFINES -mlib/master.pike -Ilib/include"
      PIKE_MODULE_PATH="$PIKE_MODULE_PATH:lib/modules"
    elif [ -f lib/pike/master.pike ]; then
      DEFINES="$DEFINES -mlib/pike/master.pike -Ilib/pike/include"
      PIKE_MODULE_PATH="$PIKE_MODULE_PATH:lib/pike/modules"
    fi
    export PIKE_MODULE_PATH
  else
    # This is useful when using several different Pikes.
    # Specify include and module paths with
    # PIKE_INCLUDE_PATH and PIKE_MODULE_PATH
    # they are handled automatically by the master,
    # so no need to do it here.
    DEFINES="$DEFINES -m$PIKE_MASTER"
  fi
fi

# Extra module-path
if [ -d etc/modules ]; then
  DEFINES="$DEFINES -Metc/modules -M../local/pmods"
fi

# Extra include-path
if [ -d etc/include ]; then
  DEFINES="$DEFINES -Ietc/include"
fi

# Extra include-path (2)
if [ -d base_server ]; then
  DEFINES="$DEFINES -Ibase_server"
fi

# Extra program-path
DEFINES="$DEFINES -P`pwd`"

# Extra kludge for HPUX
# HPUX doesn't like group 60001(nobody)
if uname | grep 'HP-UX' >/dev/null 2>&1; then
  echo 'WARNING: Applying kludge for HPUX. (see base_server/privs.pike)'
  DEFINES="$DEFINES -DHPUX_KLUDGE"
fi

gdb=no

####### END PREAMBLE

## Parse all arguments.
## GNU-style, long options only, except for -D, simply passed on.
parse_args() {
 while [ ! c"$1" = "c" ] ; do
  case $1 in
  -D*)
   DEFINES="$DEFINES $1"
  ;;
  -l*)
   ARGS="$ARGS $1"
# Used by the 'install' script
    ;;
  --quiet)
     quiet="yes"
  ;;
  --truss)
     precmd="truss "
     once=1
  ;;
  --strace)
     precmd="strace -f "
     once=1
  ;;
  --ltrace)
     precmd="ltrace -f "
     once=1
  ;;
  --log-dir=*)
   LOGDIR=`echo $1 | sed -e 's/--log-dir=//'`
  ;;
  --config-dir=*)
   DIR=`echo $1 | sed -e 's/--config-dir=//'`
   FILES=`echo $1 | sed -e's/--config-dir=//' -e's/\.//g' -e's./..g' -e 's.-..g'`
#override setting of FILES through --program:
   config_dir=1
   CAUDIUM_CONFIGDIR="$DIR"
   export CAUDIUM_CONFIGDIR
  ;;
  --pike-version=*)
   pikever=`echo $1 | sed -e 's/--pike-version=//'`
  ;;
  --pid-file=*)
   CAUDIUM_PID_FILE=`echo $1 | sed -e 's/--pid-file=//'`
   export CAUDIUM_PID_FILE
  ;;
  '--debug'|'--with-debug'|'--enable-debug')
    debug=1
  ;;
  '--without-debug')
    debug=-1
  ;;
  '--fd-debug'|'--with-fd-debug'|'--enable-fd-debug')
    DEFINES="-DFD_DEBUG $DEFINES"
  ;;
  '--threads'|'--with-threads'|'--enable-threads')
    DEFINES="-DENABLE_THREADS $DEFINES"
  ;;
  '--no-threads'|'--without-threads'|'--disable-threads')
    DEFINES="`echo $DEFINES | sed -e 's/-DENABLE_THREADS//'`"
  ;;
  '--with-profile'|'--profile')
    DEFINES="-DPROFILE $DEFINES"
  ;;
  '--with-file-profile'|'--file-profile')
    DEFINES="-DPROFILE -DFILE_PROFILE $DEFINES"
  ;;
  '--keep-alive'|'--with-keep-alive'|'--enable-keep-alive')
    DEFINES="-DKEEP_ALIVE $DEFINES"
  ;;
  '--once')
    once=1
  ;;
  '--gdb')
    gdb=gdb
    once=1
  ;;
  '--program')
    program="$2"
    program_echo="Starting $program."
# don't set FILES if the --config-dir arg is present:
    if [ "x$config_dir" = "x" ]; then
    FILES=`basename $program .pike`
    fi
    once=1
    nocaudium=1
    shift
  ;;
  -r*|-d*|-t*|-l*|-w*)
    # Argument passed along to Pike.
    ARGS="$ARGS $1"
  ;;
  -D*|-M*|-I*|-P*)
    # Argument passed along to Pike.
    DEFINES="$DEFINES $1"
  ;;
  '--version')
    VERSION=`sed <base_server/caudium.pike -e'/__caudium_version__/s/[^0-9.]*//gp' -ed|head -1`
    BUILD=`sed <base_server/caudium.pike -e'/__caudium_build__/s/[^0-9]*//gp' -ed|head -1`
    echo Caudium $VERSION.$BUILD
    exit 0
  ;;
  '--help'|'-?')
  sed -e "s/\\.B/`tput bold 2>/dev/null`/g" -e "s/B\\./`tput rmso 2>/dev/null`/g" << EOF
.BThis command will start the Caudium serverB..
d151 306
a456 2
The environment variable .BCAUDIUM_ARGSB. can be used to specify
the default arguments.
a457 1
   .BArguments:B.
d459 1
a459 1
      .B--versionB.:                  Output version information.
d461 12
a472 1
      .B--help -?B.:                  This information
a473 3
      .B--pike-version=VERB.:         Use an alternate pike version. For this to 
				  work correctly, you need a bin/caudium-VER
				  and the Caudium pike modules in lib/VER/.
d475 1
a475 1
      .B--log-dir=DIRB.:              Set the log directory. Defaults to .B../logsB..
d477 7
a483 2
      .B--config-dir=DIRB.:           Use an alternate configuration directory
				  Defaults to .B../configurationB..
d485 122
a606 1
      .B--with-threadsB.:             If threads are available, use them.
d608 23
a630 1
      .B--without-threadsB.:          Even if threads are enabled by default, 
d632 1
a632 2

      .B--with-profileB.:             Store runtime profiling information on
d634 2
a635 1
 				  not saved on permanent storage, it is only
d639 2
a640 2

      .B--with-file-profileB.:        Like .B--with-profileB., but save information 
d642 3
a644 4

      .B--with-keep-aliveB.:          Enable keep alive in the HTTP 
			          protocol module. This will soon be 
                                  the default. Some clients might have 
d647 1
a647 1
      .B--onceB.:                     Run the server only once, in the foreground.
d649 8
a656 10

      .B--gdbB.:                      Run the server in gdb. Implies .B--onceB..

      .B--programB.:                  Start a different program with the caudium
				  pike. As an example, 
                                  .B./start --program bin/install.pikeB. will 
				  start the installation program normally 
                                  started with .B./installB.

      .B--quietB.:                    Run without normal debug output from the
d660 2
a661 1
      .B--with-debugB.:               Enable debug
d663 2
a664 1
      .B--without-debugB.:            Disable all debug
d666 1
a666 2
      .B--with-fd-debugB.:            Enable FD debug.

d670 1
a670 2

      .B--pid-file=<file>B.:          Store the caudium and startscript pids in this
d674 3
a676 5

       .B-DDEFINEB.:                  Define the symbol .BDEFINEB..

       .B-d<level>B.:                 Set the runtime pike debug to level.
				  This only works if pike is compiled 
d678 6
a683 12

       .B-s<size>B.:                  Set the stack size.

       .B-M <path>B.:                 Add the path to the pike module path.

       .B-I <path>B.:                 Add the path to the pike include path.

       .B-dtB.:                       Turn of tail recursion optimization.

       .B-tB.:                        Turn on pike level tracing.

       .B-t<level>B.:                 Turn on more pike tracing. This only 
a684 2


d686 4
d691 6
a696 4
     .BCAUDIUM_CONFIGDIRB.:             Same as .B--config-dir=... B.
     .BCAUDIUM_PID_FILEB.:              Same as .B--pid-file=... B.
     .BCAUDIUM_LANGB.:                  The default language for all language
				    related tags. Defaults to 'en' for english.
d698 1
a698 157
EOF
    tput 'rmso' 2>/dev/null
    exit 0
   ;;
  *)
    pass="$pass $1"
   ;;
  esac
  shift
 done
}

# Parse arguments..
parse_args "$@@"

# Find ourselves a Pike

pike=pike
if [ "$pikever" != "" ]; then 
  if [ -x bin/caudium-$pikever ] ; then  pike=bin/caudium-$pikever; 
  elif [ -x bin/pike-$pikever ] ; then pike=bin/pike-$pikever;
  elif [ -x bin/caudium ]; then pike=bin/caudium;
  elif [ -x bin/pike ]; then pike=bin/caudium;
  else
    echo "Cannot find a pike with version $pikever"
    exit 1
  fi
else
  if [ -x bin/caudium ] ; then  pike=bin/caudium; 
  elif [ -x bin/pike ] ; then pike=bin/pike; fi
fi


PIKE_VERSION=`$pike -e 'string v; int rel;sscanf(version(), "Pike v%s release %d", v, rel); write(v+"."+rel);'`

if [ -f "lib/$PIKE_VERSION/_Caudium.so" ]; then
  DEFINES="-Mlib/$PIKE_VERSION/ $DEFINES"
else
  echo "Cannot find Caudium Pike modules for Pike version $PIKE_VERSION."
  exit 1
fi

####### END PREAMBLE

if [ ! "X$CAUDIUM_ARGS" = "X" ]; then
  if [ "$quiet" != "yes" ]; then 
    echo $$: Using $CAUDIUM_ARGS from CAUDIUM_ARGS.
  fi
  parse_args $CAUDIUM_ARGS
fi

if [ ! "X$pass" = "X" ] ; then set -- $pass ;fi

if [ "$quiet" != "yes" ]; then 
  echo $$: "$program_echo"
fi
./mkdir -p $LOGDIR/debug/

# uncomment for release version
DEBUG="-DMODULE_DEBUG -w"

if [ ! -z "$debug" ] ; then
  DEBUG="$DEBUG -DDEBUG "
fi

if [ "x$debug" = "x-1" ] ; then
  DEBUG="";
else :; fi

#
# Some useful functions
#

rotate () {
  b=5;
  for a in 4 3 2 1 ; do mv -f $1.$a $1.$b 2> /dev/null;  b=$a; done
}

start_caudium() {
  if [ "$nocaudium" = "" -a "x$DIR" != "x../configurations/" ] ; then
    args="-DCAUDIUM -DCAUDIUM_CACHE -DROXEN $DEBUG $DEFINES $ARGS $program --config-dir=$DIR $pass"
  elif [ "$nocaudium" = "1" ] ; then
     args="$DEBUG $DEFINES $ARGS $program $pass"
  else
    args="-DCAUDIUM -DCAUDIUM_CACHE -DROXEN $DEBUG $DEFINES $ARGS $program $pass"
  fi
  if [ "x$gdb" = "xno" ]; then
    if [ "$quiet" != "yes" ]; then 
      echo "PIKE_MODULE_PATH=$PIKE_MODULE_PATH"
      echo Executing $precmd$pike $args $@@
    fi
    $precmd $pike $args $@@
  else
    if [ "$quiet" != "yes" ]; then 
      echo Executing gdb $pike $args $@@
    fi
    echo >.gdbinit handle SIGPIPE nostop noprint pass
    echo >>.gdbinit handle SIGUSR1 nostop noprint pass
    echo >>.gdbinit handle SIGUSR2 nostop noprint pass
    echo >>.gdbinit run $args $@@
    gdb $pike
    rm .gdbinit
  fi
}

#
# Now do the stuff
#

if [ -z "$once" ] ; then
  cat << oo
Using configuration from $DIR, storing the debug log in $LOGDIR/debug/$FILES.1
You can use the configuration interface in the server to get debug info.
oo

  # Try to get rid of some fd's.
  # Some /bin/sh's have problems detaching otherwise.

  exec >/dev/null
  exec 2>/dev/null
  exec </dev/null

  (while : ; do
    echo $$: "Server restart at `date`"
    echo $$: "Debug log in $LOGDIR/debug/$FILES.1"
    rotate $LOGDIR/debug/$FILES

    start_caudium 2>>$LOGDIR/debug/$FILES.1 1>&2

    exitcode="$?"

    if [ "$exitcode" -eq "0" ] ; then
      # Clean shutdown.
      echo $$: "Caudium shutdown."
      exit 0
    fi
    if [ "$exitcode" -lt "0" ] ; then
      # Signal death.
      echo $$: "Caudium died of signal $exitcode. Restarting..."
    else
      # Restart. Sleep a second before restarting.
      echo $$: Caudium died. Restarting in 1 second...
      sleep 1
    fi
  done
    
  echo $$: Not Reached "famous last words"

  ) < /dev/null > $LOGDIR/debug/start_$FILES.output 2>&1 &

else
  if [ "$quiet" != "yes" ]; then 
    echo $$: "Server restart at `date`"
  fi
  start_caudium
fi
    
@


1.27
log
@updates for Lucene
@
text
@d3 1
a3 1
# $Id: start,v 1.26 2003/07/16 12:58:19 vida Exp $
@


1.26
log
@You can now add your own Pike modules in ../local/pmods. For distributions,
put them in ./local_pmods (Grendel can you test this with your debian package ?)
@
text
@d3 1
a3 1
# $Id: start,v 1.25 2003/02/27 10:11:35 jnt Exp $
d22 1
a22 1
CLASSPATH=etc/classes:etc/classes/caudium_module.jar:etc/classes/caudium_servlet.jar:etc/classes/servlet.jar:etc/classes/servlet.jar:etc/classes/jsdk.jar${CLASSPATH:+:}$CLASSPATH
@


1.25
log
@Fix kiwi's typo
@
text
@d3 1
a3 1
# $Id: start,v 1.24 2003/02/17 23:19:23 grendel Exp $
d75 1
a75 1
  DEFINES="$DEFINES -Metc/modules"
@


1.24
log
@Caudium.so became _Caudium.so
@
text
@d3 1
a3 1
# $Id: start,v 1.23 2003/02/17 23:17:51 grendel Exp $
d382 1
a382 1
    args="-DCAUDIUM -DROXEN $DEBUG $DEFINES $ARGS $program --config-dir=$DIR $pass"
d386 1
a386 1
    args="-DCAUDIUM -DROXEN $DEBUG $DEFINES $ARGS $program $pass"
@


1.23
log
@we need to be more flexible about it
@
text
@d3 1
a3 1
# $Id: start,v 1.22 2003/02/05 21:55:31 hww3 Exp $
d337 1
a337 1
if [ -f "lib/$PIKE_VERSION/Caudium.so" ]; then
@


1.22
log
@java fixes
requestid fixes
@
text
@d3 1
a3 1
# $Id: start,v 1.21 2003/02/05 18:43:46 hww3 Exp $
d323 2
@


1.21
log
@updates for java classpath
@
text
@d3 1
a3 1
# $Id: start,v 1.20 2002/12/06 15:23:54 kiwi Exp $
d22 1
a22 1
CLASSPATH=etc/classes:etc/classes/caudium_module.jar:etc/classes/caudium_servlet.jar:etc/classes/servlet.jar:etc/classes/jsdk.jar${CLASSPATH:+:}$CLASSPATH
@


1.20
log
@Typo
@
text
@d3 1
a3 1
# $Id: start,v 1.19 2002/12/06 15:05:07 kiwi Exp $
d22 1
a22 1
CLASSPATH=etc/classes:etc/classes/roxen_servlet.jar:etc/classes/jsdk.jar${CLASSPATH:+:}$CLASSPATH
@


1.19
log
@Threads are enabled per default in Darwin now.
@
text
@d3 1
a3 1
# $Id: start,v 1.18 2002/11/20 19:27:23 vida Exp $
d38 1
a38 1
elfi [ "$OSTYPE" = "Darwin" ]; then
@


1.18
log
@boo
@
text
@d3 1
a3 1
# $Id: start,v 1.17 2002/11/20 19:19:02 vida Exp $
d37 3
@


1.17
log
@Caudium didn't start if it wasn't launch from caudium base dir or from /, ie it
didn't work from directory like /usr/local.
Is dirname available on all sh ? (I can't use pike since pwd is used for pike
detection)
@
text
@d3 1
a3 1
# $Id: start,v 1.16 2002/08/30 01:47:05 hww3 Exp $
d21 1
a21 1
  # Make sure $CLASSPATH contains the servlet stuff
@


1.16
log
@incorrect startup environment (-DCAUDIUM) when running install script.
@
text
@d3 1
a3 1
# $Id: start,v 1.15 2002/06/20 16:23:22 kazmer Exp $
d17 5
a21 1
# Make sure $CLASSPATH contains the servlet stuff
a330 5
CAUDIUM_CWD=`$pike -e "write(dirname(\"$0\"));"`

if [ -n "$CAUDIUM_CWD" ]; then
  cd $CAUDIUM_CWD
fi
@


1.15
log
@

tidier platform detection. hope it's gonna be ok everywhere (tested on
linux, freebsd, solaris and openbsd whatever they had as /bin/sh and sed
on the path)
@
text
@d3 1
a3 1
# $Id: start,v 1.14 2002/06/19 17:57:58 kiwi Exp $
d379 2
@


1.14
log
@Threads are enabled now on Linux and FreeBSD
@
text
@d3 1
a3 1
# $Id: start,v 1.13 2002/05/03 15:54:26 grendel Exp $
d21 13
a33 9
# Enable threads (if available) on Solaris.
# Most other OS's have thread bugs that cause them or Caudium to crash.
if uname | grep 'SunOS' >/dev/null 2>&1; then
  if uname -r | grep '5\.[5-9]' >/dev/null 2>&1; then
    if [ x"$1" != "x--help" ] ; then
      echo 'Solaris 2.5 or later detected. Enabling threads (if available).'
    fi
    DEFINES="$DEFINES -DENABLE_THREADS"
  fi
a34 22

# Enable thread (if available) on Linux
if uname | grep 'Linux' >/dev/null 2>&1; then
  if uname -r | grep '2\.[2-9]' >/dev/null 2>&1; then
    if [ x"$1" != "x--help" ] ; then
      echo 'Linux 2.2 or later detected. Enabling threads (if available).'
    fi
    DEFINES="$DEFINES -DENABLE_THREADS"
  fi
fi

# Enable thread (if available) on FreeBSD
if uname | grep 'FreeBSD' >/dev/null 2>&1; then
  if uname -r | grep '[45]\.[0-9]' >/dev/null 2>&1; then
    if [ x"$1" != "x--help" ] ; then
      echo 'FreeBSD 4.0 or later detected. Enabling threads (if available).'
    fi
    DEFINES="$DEFINES -DENABLE_THREADS"
  fi
fi


@


1.13
log
@attempt to cure the bug Vida stumbled accross
@
text
@d3 1
a3 1
# $Id: start,v 1.12 2001/05/31 18:21:14 neotron Exp $
d31 22
@


1.12
log
@Fixed various warnings, printing of warnings and some other bugs.
@
text
@d3 1
a3 1
# $Id: start,v 1.11 2001/02/13 20:46:35 neotron Exp $
d323 5
@


1.12.2.1
log
@same as for 1.3
@
text
@d3 1
a3 1
# $Id: start,v 1.12 2001/05/31 18:21:14 neotron Exp $
d321 1
a322 5
CAUDIUM_CWD=`$pike -e "write(dirname(\"$0\"));"`

if [ -n "$CAUDIUM_CWD" ]; then
  cd $CAUDIUM_CWD
fi
@


1.12.2.2
log
@
Tracing with ktrace for darwin.
@
text
@d3 1
a3 1
# $Id: start,v 1.12.2.1 2002/05/03 16:26:25 grendel Exp $
a117 7
  # darwin
  --ktrace)
    precmd="ktrace -d "
    once=1;
    echo "Tracing in the file ktrace.out"
    echo "The trace file is not human readable; use kdump(1) to decode it."
  ;;
d255 1
a255 1
      .B--truss,--strace,--ltrace,--ktraceB.: Run the server under the selected tracer
@


1.12.2.3
log
@
ktrace isn't a darwinism
@
text
@d3 1
a3 1
# $Id: start,v 1.12.2.2 2004/01/20 21:47:30 bertrand Exp $
d118 1
@


1.11
log
@Some fixes to start and install scripts.
@
text
@d3 1
a3 1
# $Id: start,v 1.10 2000/11/19 04:21:13 kiwi Exp $
d347 5
a351 4
if [ -z "$debug" ] ; then
  DEBUG="-DMODULE_DEBUG";
else
  DEBUG="-DDEBUG -DMODULE_DEBUG"
@


1.10
log
@Now --with-debug works...
@
text
@d3 1
a3 1
# $Id: start,v 1.9 2000/09/25 19:11:45 neotron Exp $
d126 2
d187 2
a188 2
    VERSION=`sed <base_server/roxen.pike -e'/__caudium_version__/s/[^0-9.]*//gp' -ed|head -1`
    BUILD=`sed <base_server/roxen.pike -e'/__caudium_build__/s/[^0-9]*//gp' -ed|head -1`
@


1.10.4.1
log
@Removed MODULE_DEBUG from start script.
@
text
@d3 1
a3 1
# $Id: start,v 1.10 2000/11/19 04:21:13 kiwi Exp $
d346 1
a346 1
  DEBUG="";
@


1.10.4.2
log
@Some fixes to start and install scripts.
@
text
@d3 1
a3 1
# $Id: start,v 1.10.4.1 2000/12/13 06:14:14 neotron Exp $
a125 2
   CAUDIUM_CONFIGDIR="$DIR"
   export CAUDIUM_CONFIGDIR
d185 2
a186 2
    VERSION=`sed <base_server/caudium.pike -e'/__caudium_version__/s/[^0-9.]*//gp' -ed|head -1`
    BUILD=`sed <base_server/caudium.pike -e'/__caudium_build__/s/[^0-9]*//gp' -ed|head -1`
@


1.9
log
@fixed ultrasum stuff
@
text
@d3 1
a3 1
# $Id: start,v 1.8 2000/09/11 23:46:05 neotron Exp $
d366 1
a366 1
    args="-DCAUDIUM -DROXEN $DEFINES $ARGS $program --config-dir=$DIR $pass"
d368 1
a368 1
    args="-DCAUDIUM -DROXEN $DEFINES $ARGS $program $pass"
@


1.8
log
@Added quiet option to the start script - mainly for --program.
@
text
@d3 1
a3 1
# $Id: start,v 1.7 2000/08/13 07:40:53 embee Exp $
d173 1
d365 1
a365 1
  if [ "x$DIR" != "x../configurations/" ] ; then
@


1.7
log
@  fixed startupmessage to say which program is actually started
  if a different program than caudium is started, the debuglog filename
     is set according to the basename of the program started
@
text
@d3 1
a3 1
# $Id: start,v 1.6 2000/08/12 08:36:33 neotron Exp $
d103 3
d230 1
a230 1

d242 4
d331 3
a333 1
  echo $$: Using $CAUDIUM_ARGS from CAUDIUM_ARGS.
d339 3
a341 3

echo $$: "$program_echo"

d370 4
a373 2
    echo "PIKE_MODULE_PATH=$PIKE_MODULE_PATH"
    echo Executing $precmd$pike $args $@@
d376 3
a378 1
    echo Executing gdb $pike $args $@@
d434 3
a436 1
  echo $$: "Server restart at `date`"
@


1.6
log
@fixed start script
@
text
@d3 1
a3 1
# $Id: start,v 1.5 2000/08/09 21:24:50 neotron Exp $
d10 1
d121 2
d164 5
d331 1
a331 1
echo $$: Starting the Caudium Challenger World Wide Web server.
@


1.5
log
@Really fixed shared makefiles. Also install .so modules in
prefix/caudium/server/lib/<pikeversion>/ and modified start script accordingly.
Finally, it is now possible to install multiple pike versions at once (kinda.
See ./start --help for details (flag is pike-version).
@
text
@d3 1
a3 1
# $Id: start,v 1.4 2000/08/07 04:05:49 neotron Exp $
d98 2
d101 1
d103 2
a104 1
     precmd="truss $pike"
d107 2
a108 1
     precmd="strace -f $pike"
d110 3
a112 8
  --no-env-setup)
   pass2="$pass2 $1"
  ;;
  --recheck-env)
   pass2="$pass2 $1"
  ;;
  --variable=*)
   pass2="$pass2 `echo $1 | sed -e 's/--variable=//'`"
d153 1
a153 1
    once=1http://www.gnome.org/screenshots/gwp.jpg
d161 1
d164 8
d179 1
a179 1
  sed -e "s/\\.B/`tput 'bold' 2>/dev/null`/g" -e "s/B\\./`tput 'rmso' 2>/dev/null`/g" << EOF
d237 3
a239 4
      .B--trussB.:                    (Solaris only). Run the server under
				  truss, shows .BallB. system calls. This is 
				  extremely noisy, and is not intented for 
				  anything but debug.
d347 5
a351 1
  args="-DCAUDIUM -DROXEN $DEBUG $DEFINES $pass $program --config-dir=$DIR $pass2"
d354 2
a355 2
    echo Executing $pike $args $@@
    $pike $args $@@
@


1.4
log
@Define ROXEN as well
@
text
@d3 1
a3 1
# $Id: start,v 1.3 2000/08/07 00:50:42 neotron Exp $
a85 7
pike=pike
if [ -x bin/pike ] ; then pike=bin/pike; fi
if [ -x bin/caudium ] ; then  pike=bin/caudium; fi
if [ "x$PIKE" = "x" ]; then :; else
  if [ -x "$PIKE" ]; then pike="$PIKE"; fi
fi

d100 4
a103 1
     pike="truss $pike"
d121 3
d182 4
d263 1
a263 1
				  related tags. Defaults to 'en' for english.
d277 28
a305 2

parse_args $@@
@


1.3
log
@major changes, caudium -> roxen. some 7.0 changes
@
text
@d3 1
a3 1
# $Id: start,v 1.2 2000/08/04 01:42:41 neotron Exp $
d310 1
a310 1
  args="-DCAUDIUM $DEBUG $DEFINES $pass $program --config-dir=$DIR $pass2"
@


1.2
log
@some replacement of Roxen->Caudium
@
text
@d3 1
a3 1
# $Id: start,v 1.1.1.1 2000/07/28 16:31:07 neotron Exp $
d9 1
a9 1
program=base_server/roxenloader.pike
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
# $Id: start,v 1.58 1999/08/11 06:26:54 peter Exp $
d21 1
a21 1
# Most other OS's have thread bugs that cause them or Roxen to crash.
d31 1
a31 1
# Roxen will create files as the initial user,
d88 1
a88 1
if [ -x bin/roxen ] ; then  pike=bin/roxen; fi
d126 2
a127 2
   ROXEN_PID_FILE=`echo $1 | sed -e 's/--pid-file=//'`
   export ROXEN_PID_FILE
d165 3
a167 3
    VERSION=`sed <base_server/roxen.pike -e'/__roxen_version__/s/[^0-9.]*//gp' -ed|head -1`
    BUILD=`sed <base_server/roxen.pike -e'/__roxen_build__/s/[^0-9]*//gp' -ed|head -1`
    echo Roxen Challenger $VERSION.$BUILD
d172 1
a172 1
.BThis command will start the Roxen serverB..
d174 1
a174 1
The environment variable .BROXEN_ARGSB. can be used to specify
d213 1
a213 1
      .B--programB.:                  Start a different program with the roxen
d230 2
a231 2
      .B--pid-file=<file>B.:          Store the roxen and startscript pids in this
				  file. Defaults to .B/tmp/roxen_\$UIDB.
d257 3
a259 3
     .BROXEN_CONFIGDIRB.:             Same as .B--config-dir=... B.
     .BROXEN_PID_FILEB.:              Same as .B--pid-file=... B.
     .BROXEN_LANGB.:                  The default language for all language
d278 3
a280 3
if [ ! "X$ROXEN_ARGS" = "X" ]; then
  echo $$: Using $ROXEN_ARGS from ROXEN_ARGS.
  parse_args $ROXEN_ARGS
d286 1
a286 1
echo $$: Starting the Roxen Challenger World Wide Web server.
d309 2
a310 2
start_roxen() {
  args="-DROXEN $DEBUG $DEFINES $pass $program --config-dir=$DIR $pass2"
d348 1
a348 1
    start_roxen 2>>$LOGDIR/debug/$FILES.1 1>&2
d354 1
a354 1
      echo $$: "Roxen shutdown."
d359 1
a359 1
      echo $$: "Roxen died of signal $exitcode. Restarting..."
d362 1
a362 1
      echo $$: Roxen died. Restarting in 1 second...
d373 1
a373 1
  start_roxen
@


1.1.1.1
log
@Roxen 1.3 imported
@
text
@@
