From toha@ib.com.ua  Thu Dec 16 10:05:44 2004
Return-Path: <toha@ib.com.ua>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CFEC616A4CF
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 16 Dec 2004 10:05:44 +0000 (GMT)
Received: from ib.com.ua (ib.com.ua [217.144.67.33])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B3D1F43D2D
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 16 Dec 2004 10:05:43 +0000 (GMT)
	(envelope-from toha@ib.com.ua)
Received: from ib.com.ua (localhost.ib.com.ua [127.0.0.1])
	by ib.com.ua (8.13.1/8.12.10) with ESMTP id iBGA5Ton049205
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 16 Dec 2004 12:05:29 +0200 (EET)
	(envelope-from toha@ib.com.ua)
Received: (from toha@localhost)
	by ib.com.ua (8.13.1/8.12.10/Submit) id iBGA5OTE049204;
	Thu, 16 Dec 2004 12:05:24 +0200 (EET)
	(envelope-from toha)
Message-Id: <200412161005.iBGA5OTE049204@ib.com.ua>
Date: Thu, 16 Dec 2004 12:05:24 +0200 (EET)
From: Anton Yudin <toha@toha.org.ua>
Reply-To: Anton Yudin <toha@toha.org.ua>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: There is no way to specify jvm parameters when starting jakarta-tomcat.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         75143
>Category:       ports
>Synopsis:       There is no way to specify jvm parameters when starting jakarta-tomcat.
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    lawrance
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 16 10:10:18 GMT 2004
>Closed-Date:    Tue Feb 07 08:59:30 GMT 2006
>Last-Modified:  Tue Feb 07 08:59:30 GMT 2006
>Originator:     Anton Yudin
>Release:        FreeBSD 4.10-STABLE i386
>Organization:
>Environment:
System: FreeBSD .ua 4.10-STABLE FreeBSD 4.10-STABLE #0: Fri Oct 15 17:10:27 EEST 2004 root@.ua:/obj/usr/src/sys/ i386


	
>Description:
	There is no way to specify jvm parameters when starting jakarta-tomcat.
	
>How-To-Repeat:
	
>Fix:
	Patch www/jakarta-tomcat5/Makefile and www/jakarta-tomcat4/files/daemonctl.c

	Now it is possible to specify parameters for jvm in such way:
	tomcat50ctl start [jvm-arguments]
	for example:
	tomcat50ctl start -server -Xmx128m

*** www/jakarta-tomcat5/Makefile.original	Tue Dec 14 16:38:37 2004
--- www/jakarta-tomcat5/Makefile	Tue Dec 14 16:18:02 2004
***************
*** 124,131 ****
  
  	@${ECHO_CMD} -n ">> Compiling and installing control program..."
  	@${SED} \
! 	-e "/%%JAVA_ARGS%%/s//\"-Dcatalina.home=${APP_HOME:S/\//\\\//g}\",/g" \
! 	-e "/%%JAR_ARGS%%/s//\"start\",/g" \
  	${WRKDIR}/daemonctl.c > ${WRKDIR}/daemonctl_.c
  	@cd ${WRKDIR} && ${CC} -ansi -o ${CONTROL_SCRIPT_NAME} daemonctl_.c
  	@${CP} ${WRKDIR}/${CONTROL_SCRIPT_NAME} ${CONTROL_SCRIPT}
--- 124,131 ----
  
  	@${ECHO_CMD} -n ">> Compiling and installing control program..."
  	@${SED} \
! 	-e "/%%JAVA_ARGS%%/s//-Dcatalina.home=${APP_HOME:S/\//\\\//g}/g" \
! 	-e "/%%JAR_ARGS%%/s//start/g" \
  	${WRKDIR}/daemonctl.c > ${WRKDIR}/daemonctl_.c
  	@cd ${WRKDIR} && ${CC} -ansi -o ${CONTROL_SCRIPT_NAME} daemonctl_.c
  	@${CP} ${WRKDIR}/${CONTROL_SCRIPT_NAME} ${CONTROL_SCRIPT}

*** www/jakarta-tomcat4/files/daemonctl.c.original	Thu Oct 10 02:10:32 2002
--- www/jakarta-tomcat4/files/daemonctl.c	Thu Dec 16 11:48:24 2004
***************
*** 57,62 ****
--- 57,64 ----
  private void restart(void);
  
  
+ char** applicationArguments = NULL;
+ 
  /**
   * Main function. This function is called when this program is executed.
   *
***************
*** 84,93 ****
--- 86,97 ----
  
  	argument = argv[1];
  	if (strcmp("start", argument) == 0) {
+ 		applicationArguments = argv + 2;
  		start();
  	} else if (strcmp("stop", argument) == 0) {
  		stop();
  	} else if (strcmp("restart", argument) == 0) {
+ 		applicationArguments = argv + 2;
  		restart();
  	} else {
  		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Illegal argument \"%s\".\n", argument);
***************
*** 313,318 ****
--- 317,325 ----
  	int stdoutLogFile;
  	int stderrLogFile;
  	struct stat sb;
+ 	char** arguments = NULL;
+ 	int ac = 0;
+ 	int i = 0;
  
  	/* Open and read the PID file */
  	printf(">> Reading PID file (%%PID_FILE%%)...");
***************
*** 415,420 ****
--- 422,449 ----
  
  	if (pid == 0) {
  
+ 		if (applicationArguments != NULL)
+ 			for (;applicationArguments[ac] != NULL;ac++)
+ 
+ 		fprintf(stderr, "ac = %i\n", ac);
+ 
+ 		arguments = malloc(sizeof(char*) * 6 + ac);
+ 
+ 		arguments[0] = "%%JAVA_HOME%%/%%JAVA_CMD%%";
+ 		for (i = 0; i < ac; i++)
+ 			arguments[1 + i] = applicationArguments[i];
+ 		arguments[1 + i] = "-jar";
+ 		arguments[2 + i] = "%%JAVA_ARGS%%";
+ 		arguments[3 + i] = "%%JAR_FILE%%";
+ 		arguments[4 + i] = "%%JAR_ARGS%%";
+ 		arguments[5 + i] = NULL;
+ 
+ #ifdef DEBUG
+ 		for (ac = 0; ac < i + 5; ac++) {
+ 			fprintf(stderr, "arg[%i] = (%s)\n", ac, arguments[ac]);
+ 		}
+ #endif
+ 
  		/* Redirect stdout to log file */
  		dup2(stdoutLogFile, STDOUT_FILENO);
  
***************
*** 425,431 ****
  		         file using pipe(2) */
  
  		/* Execute the command */
! 		execl("%%JAVA_HOME%%/%%JAVA_CMD%%", "%%JAVA_HOME%%/%%JAVA_CMD%%", "-jar", %%JAVA_ARGS%% "%%JAR_FILE%%", %%JAR_ARGS%% NULL);
  
  		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to start %%APP_TITLE%% %%PORTVERSION%% since '%%JAVA_HOME%%/%%JAVA_CMD%% -jar %%JAR_FILE%%' in %%APP_HOME%%: ");
  		perror(NULL);
--- 454,460 ----
  		         file using pipe(2) */
  
  		/* Execute the command */
! 		execv("%%JAVA_HOME%%/%%JAVA_CMD%%", arguments);
  
  		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to start %%APP_TITLE%% %%PORTVERSION%% since '%%JAVA_HOME%%/%%JAVA_CMD%% -jar %%JAR_FILE%%' in %%APP_HOME%%: ");
  		perror(NULL);
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->hq 
Responsible-Changed-By: hq 
Responsible-Changed-When: Thu Dec 16 15:57:23 GMT 2004 
Responsible-Changed-Why:  
I'll handle this as I'm already taking care of other tomcat related PRs. 

BTW, this port has a maintainer, so please CC him when sending a PR related to 
Tomcat. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=75143 

From: "Kang Liu" <liukang@bjut.edu.cn>
To: <freebsd-gnats-submit@FreeBSD.org>, <toha@toha.org.ua>
Cc:  
Subject: Re: ports/75143: There is no way to specify jvm parameters when starting jakarta-tomcat.
Date: Fri, 17 Dec 2004 00:54:39 +0800

 There are plenty of daemonctl related PRs, e.g. PR:59571, PR: 38018 , PR:53790.
 I'm working on this issue now. 
 Since it would probably affect all version of jakarta-tomcat, 
 I'd like to make a beta patch and post it to freebsd-java first. 
 
 Kang
 
 

From: Anton Yudin <toha@toha.org.ua>
To: freebsd-gnats-submit@FreeBSD.org, liukang@bjut.edu.cn,
	toha@toha.org.ua
Cc:  
Subject: Re: ports/75143: There is no way to specify jvm parameters when starting jakarta-tomcat.
Date: Fri, 17 Dec 2004 15:17:56 +0200 (EET)

 >
 > There are plenty of daemonctl related PRs, e.g. PR:59571, PR: 38018 , PR:53790.
 > I'm working on this issue now. 
 > Since it would probably affect all version of jakarta-tomcat, 
 > I'd like to make a beta patch and post it to freebsd-java first. 
 >
 > Kang
 >
 Okay, but, please, look at my patch. it's simple and very useful.
 

From: "Kang Liu" <liukang@bjpu.edu.cn>
To: <freebsd-gnats-submit@FreeBSD.org>, <toha@toha.org.ua>
Cc: "'Herve Quiroz'" <herve.quiroz@esil.univ-mrs.fr>,
	<delphij@freebsd.org>
Subject: Re: ports/75143: There is no way to specify jvm parameters when starting jakarta-tomcat.
Date: Mon, 21 Mar 2005 00:07:06 +0800

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0007_01C52DA9.EBA59EF0
 Content-Type: text/plain;
 	charset="US-ASCII"
 Content-Transfer-Encoding: 7bit
 
 The attachment is a new daemonctl for tomcat mainly based on Anton 's patch,
 also with the fix for PR:ports/38020 . There might be some bugs in that
 file, while I think it could be better if I post a *draft* version here.
 Any suggestion is welcome.
 
 
 Kang
 
 For the memory of SMTH BBS...
 
 ------=_NextPart_000_0007_01C52DA9.EBA59EF0
 Content-Type: text/plain;
 	name="daemonctl.c"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="daemonctl.c"
 
 /*
  * -*- mode: Fundamental; tab-width: 4; -*-
  * ex:ts=3D4
  *
  * Daemon control program.
  *
  * $FreeBSD: ports/www/jakarta-tomcat4/files/daemonctl.c,v 1.10 =
 2002/10/09 23:10:32 znerd Exp $
  */
 
 #include <assert.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <syslog.h>
 #include <unistd.h>
 #include <sys/errno.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/uio.h>
 
 /* The maximum size of the PID file, in bytes */
 #define MAX_FILE_SIZE			32
 
 /* The interval in seconds between the checks to make sure the process
    died after a kill */
 #define STOP_TIME_INTERVAL		1
 
 #define ERR_ILLEGAL_ARGUMENT				1
 #define ERR_PID_FILE_NOT_FOUND				2
 #define ERR_PID_FILE_TOO_LARGE				3
 #define ERR_PID_FILE_CONTAINS_ILLEGAL_CHAR	4
 #define ERR_KILL_FAILED						5
 #define ERR_ALREADY_RUNNING					6
 #define ERR_NOT_RUNNING						7
 #define ERR_CHDIR_TO_APP_HOME				8
 #define ERR_ACCESS_JAR_FILE					17
 #define ERR_STDOUT_LOGFILE_OPEN				9
 #define ERR_STDERR_LOGFILE_OPEN				10
 #define ERR_FORK_FAILED						11
 #define ERR_STAT_JAVA_HOME					12
 #define ERR_JAVA_HOME_NOT_DIR				13
 #define ERR_STAT_JAVA_CMD					14
 #define ERR_JAVA_CMD_NOT_FILE				15
 #define ERR_JAVA_CMD_NOT_EXECUTABLE			16
 
 #define private static
 
 private void printUsage(void);
 private int openPIDFile(void);
 private int readPID(int);
 private void writePID(int file, int pid);
 private void start(void);
 private void stop(void);
 private void restart(void);
 
 
 char** applicationArguments =3D NULL;
 
 /**
  * Main function. This function is called when this program is executed.
  *
  * @param argc
  *    the number of arguments plus one, so always greater than 0.
  *
  * @param argv
  *    the arguments in an array of character pointers, where the last =
 argument
  *    element is followed by a NULL element.
  */
 int main(int argc, char *argv[]) {
 
 	/* Declare variables, like all other good ANSI C programs do :) */
 	char *argument;
 
 	/* Parse the arguments */
 	if (argc < 2) {
 		printUsage();
 		return 0;
 	}
 
 	/* XXX: Fix for setting up the environment for the java wrapper script =
 */
 	setuid(geteuid());
 	setgid(getegid());
 
 	argument =3D argv[1];
 	if (strcmp("start", argument) =3D=3D 0) {
 		applicationArguments =3D argv + 2;
 		start();
 	} else if (strcmp("stop", argument) =3D=3D 0) {
 		stop();
 	} else if (strcmp("restart", argument) =3D=3D 0) {
 		applicationArguments =3D argv + 2;
 		restart();
 	} else {
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Illegal argument \"%s\".\n", =
 argument);
 		printUsage();
 		exit(ERR_ILLEGAL_ARGUMENT);
 	}
 
 	return 0;
 }
 
 
 /**
  * Prints usage information to stdout.
  */
 void printUsage(void) {
 	printf("Usage: %%CONTROL_SCRIPT_NAME%% [ start | stop | restart ]\n");
 }
 
 /**
  * Check tomcat and java related environment.
  */
 void CheckTomcatJavaEnv(void) {
 	int result;
 	struct stat sb;
 	/* Check if the JDK home directory is actually a directory */
 	result =3D stat("%%JAVA_HOME%%", &sb);
 	if (result !=3D 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to stat =
 %%JAVA_HOME%%: ");
 		perror(NULL);
 		exit(ERR_STAT_JAVA_HOME);
 	}
 	if (!S_ISDIR(sb.st_mode)) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java home directory =
 %%JAVA_HOME%% is not a directory.\n");
 		exit(ERR_JAVA_HOME_NOT_DIR);
 	}
 
 	/* Check if the Java command is actually an executable regular file */
 	result =3D stat("%%JAVA_HOME%%/%%JAVA_CMD%%", &sb);
 	if (result !=3D 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to stat =
 %%JAVA_HOME%%/%%JAVA_CMD%%: ");
 		perror(NULL);
 		exit(ERR_STAT_JAVA_CMD);
 	}
 	if (!S_ISREG(sb.st_mode)) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java command =
 %%JAVA_HOME%%/%%JAVA_CMD%% is not a regular file.\n");
 		exit(ERR_JAVA_CMD_NOT_FILE);
 	}
 	result =3D access("%%JAVA_HOME%%/%%JAVA_CMD%%", X_OK);
 	if (result !=3D 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java command =
 %%JAVA_HOME%%/%%JAVA_CMD%% is not executable: ");
 		perror(NULL);
 		exit(ERR_JAVA_CMD_NOT_EXECUTABLE);
 	}
 
 	/* Change directory */
 	result =3D chdir("%%APP_HOME%%");
 	if (result < 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to access directory =
 %%APP_HOME%%: ");
 		perror(NULL);
 		exit(ERR_CHDIR_TO_APP_HOME);
 	}
 
 	/* See if the JAR file exists */
 	result =3D access("%%APP_HOME%%/%%JAR_FILE%%", R_OK);
 	if (result < 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to access JAR file =
 %%APP_HOME%%/%%JAR_FILE%%: ");
 		perror(NULL);
 		exit(ERR_ACCESS_JAR_FILE);
 	}
 }
 
 /**
  * Attempts to open the stdout log file. If that file is successfully =
 opened, then
  * the file handle (an int) will be returned.
  *
  * @return
  *    the file handle.
  */
 int openStdoutLogFile(void) {
 
  	int file;
 
 	/* Attempt to open the stdout log file */
 	file =3D open("%%STDOUT_LOG%%", O_WRONLY);
 	if (file < 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to open =
 %%STDOUT_LOG%% for writing: ");
 		perror(NULL);
 		exit(ERR_PID_FILE_NOT_FOUND);
 	}
 
 	return file;
 }
 
 /**
  * Attempts to open the stderr log file. If that file is successfully =
 opened, then
  * the file handle (an int) will be returned.
  *
  * @return
  *    the file handle.
  */
 int openStderrLogFile(void) {
 
  	int file;
 
 	/* Attempt to open the stderr log file */
 	file =3D open("%%STDERR_LOG%%", O_WRONLY);
 	if (file < 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to open =
 %%STDERR_LOG%% for writing: ");
 		perror(NULL);
 		exit(ERR_PID_FILE_NOT_FOUND);
 	}
 
 	return file;
 }
 
 
 /**
  * Attempts to open the PID file. If that file is successfully opened, =
 then
  * the file handle (an int) will be returned.
  *
  * @return
  *    the file handle.
  */
 int openPIDFile(void) {
 
  	int file;
 
 	/* Attempt to open the PID file */
 	file =3D open("%%PID_FILE%%", O_RDWR);
 	if (file < 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to open %%PID_FILE%% =
 for reading and writing: ");
 		perror(NULL);
 		exit(ERR_PID_FILE_NOT_FOUND);
 	}
 
 	return file;
 }
 
 
 /**
  * Reads a PID from the specified file. The file is identified by a file
  * handle.
  *
  * @param file
  *    the file handle.
  *
  * @return
  *    the PID, or -1 if the file was empty.
  */
 int readPID(int file) {
 
 	char *buffer;
 	int hadNewline =3D 0;
 	unsigned int count;
 	unsigned int i;
 	int pid;
 
 	/* Read the PID file contents */
 	buffer =3D (char *) malloc((MAX_FILE_SIZE + 1) * sizeof(char));
 	count =3D read(file, buffer, MAX_FILE_SIZE + 1);
 	if (count > MAX_FILE_SIZE) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: The file %%PID_FILE%% =
 contains more than %d bytes.\n", MAX_FILE_SIZE);
 		exit(ERR_PID_FILE_TOO_LARGE);
 	}
 
 	/* Convert the bytes to a number */
 	pid =3D 0;
 	for (i=3D0; i<count; i++) {
 		char c =3D buffer[i];
 		if (c >=3D '0' && c <=3D '9') {
 			char digit =3D c - '0';
 			pid *=3D 10;
 			pid +=3D digit;
 		} else if (i =3D=3D (count - 1) && c =3D=3D '\n') {
 			/* XXX: Ignore a newline at the end of the file */
 			hadNewline =3D 1;
 		} else {
 			printf(" [ FAILED ]\n");
 			fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: The file %%PID_FILE%% =
 contains an illegal character (%d) at position %d.\n", c, i);
 			exit(ERR_PID_FILE_CONTAINS_ILLEGAL_CHAR);
 		}
 	}
 	printf(" [ DONE ]\n");
 
 	if (count =3D=3D 0 || (count =3D=3D 1 && hadNewline =3D=3D 1)) {
 		return -1;
 	}
 
 	return pid;
 }
 
 
 /**
  * Writes a process ID to the specified file. The file is identified by =
 a file
  * handle.
  *
  * @param file
  *    the file handle, always greater than 0.
  *
  * @param pid
  *    the PID to store, always greater than 0.
  */
 void writePID(int file, int pid) {
 
 	char *buffer;
 	int nbytes;
 
 	/* Check preconditions */
 	assert(file > 0);
 	assert(pid > 0);
 
 	printf(">> Writing PID file...");
 
 	lseek(file, (off_t) 0, SEEK_SET);
 	ftruncate(file, (off_t) 0);
 	nbytes =3D asprintf(&buffer, "%d\n", pid);
 	write(file, buffer, nbytes);
 	printf(" [ DONE ]\n");
 }
 
 
 /**
  * Checks if the specified process is running.
  *
  * @param pid
  *    the process id, greater than 0.
  *
  * @return
  *    0 if the specified process is not running, a different value =
 otherwise.
  */
 int existsProcess(int pid) {
 
 	int result;
 
 	/* Check preconditions */
 	assert(pid > 0);
 
 	/* See if the process exists */
    	result =3D kill(pid, 0);
 
 	/* If the result is 0, then the process exists */
 	if (result =3D=3D 0) {
 		return 1;
 	} else {
 		return 0;
 	}
 }
 
 
 /**
  * Kills the process identified by the specified ID.
  *
  * @param pid
  *    the process id, greater than 0.
  */
 void killProcess(int pid) {
 
 	int result;
 	unsigned int waited;
 	unsigned int forced;
 	unsigned int interval =3D STOP_TIME_INTERVAL;
 	unsigned int timeout  =3D %%STOP_TIMEOUT%%;
 
 	/* Check preconditions */
 	assert(pid > 0);
 
 	printf(">> Terminating process %d...", pid);
 	result =3D kill(pid, SIGTERM);
 	if (result < 0) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to kill process %d: =
 ", pid);
 		perror(NULL);
 		exit(ERR_KILL_FAILED);
 	}
 
 	/* Wait until the process is actually killed */
     result =3D existsProcess(pid);
 	for (waited=3D0; result =3D=3D 1 && waited < timeout; waited +=3D =
 interval)
 	{
 		printf(".");
 		fflush(NULL);
 		sleep(interval);
     	result =3D existsProcess(pid);
 	}
 
 	/* If the process still exists, then have no mercy and kill it */
 	forced =3D 0;
 	if (result =3D=3D 1) {
 
 		/* Force the process to die */
 		result =3D kill(pid, SIGKILL);
 		if (result =3D=3D 0) {
 			forced =3D 1;
 			printf(" [ DONE ]\n");
 			fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Process %d did not =
 terminate within %%STOP_TIMEOUT%% sec. Killed.\n", pid);
 		} else if (result !=3D ESRCH) {
 			printf(" [ FAILED ]\n");
 			fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to kill process %d: =
 ", pid);
 			perror(NULL);
 			exit(ERR_KILL_FAILED);
 		}
 	}
 
 	if (forced =3D=3D 0) {
 		printf(" [ DONE ]\n");
 	}
 }
 
 
 /**
  * Starts the daemon.
  */
 void start(void) {
 
 	int file;
 	int pid;
 	int result;
 	int stdoutLogFile;
 	int stderrLogFile;
 	struct stat sb;
 	char** arguments =3D NULL;
 	int ac =3D 0;
 	int i =3D 0;
 
 	/* Open and read the PID file */
 	printf(">> Reading PID file (%%PID_FILE%%)...");
 	file =3D openPIDFile();
 	pid =3D readPID(file);
 
 	printf(">> Starting %%APP_TITLE%% %%PORTVERSION%%...");
 	if (pid !=3D -1) {
 
 		/* Check if the process actually exists */
 		result =3D existsProcess(pid);
 		if (result =3D=3D 1) {
 			printf(" [ FAILED ]\n");
 			fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: %%APP_TITLE%% =
 %%PORTVERSION%% is already running, PID is %d.\n", pid);
 			exit(ERR_ALREADY_RUNNING);
 		}
 	}
 
 	/* Check tomcat and java related files */
 	CheckTomcatJavaEnv();
 
 	/* Open Log Files*/
 	stdoutLogFile =3D openStdoutLogFile();
 	stderrLogFile =3D openStderrLogFile();
 
 	/* Split this process in two */
 	pid =3D fork();
 	if (pid =3D=3D -1) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to fork: ");
 		perror(NULL);
 		exit(ERR_FORK_FAILED);
 	}
 
 	if (pid =3D=3D 0) {
 
 		if (applicationArguments !=3D NULL)
 			for (;applicationArguments[ac] !=3D NULL;ac++)
 
 		arguments =3D malloc(sizeof(char*) * 6 + ac);
 
 		arguments[0] =3D "%%JAVA_HOME%%/%%JAVA_CMD%%";
 		for (i =3D 0; i < ac; i++)
 			arguments[0 + i] =3D applicationArguments[i];
 		arguments[1 + i] =3D "-jar";
 		arguments[2 + i] =3D %%JAVA_ARGS%%;
 		arguments[3 + i] =3D "%%APP_HOME%%/%%JAR_FILE%%";
 		arguments[4 + i] =3D %%JAR_ARGS%%;
 		arguments[5 + i] =3D NULL;
 
 #ifdef DEBUG
 		for (ac =3D 0; ac < i + 5; ac++) {
 			fprintf(stderr, "arg[%i] =3D (%s)\n", ac, arguments[ac]);
 		}
 #endif
 
 		/* Redirect stdout to log file */
 		dup2(stdoutLogFile, STDOUT_FILENO);
 
 		/* Redirect stderr to log file */
 		dup2(stderrLogFile, STDERR_FILENO);
 
 		/* TODO: Support redirection of both stdout and stderr to the same
 		         file using pipe(2) */
 
 		/* Execute the command */
 		execv("%%JAVA_HOME%%/%%JAVA_CMD%%", arguments);
 		free(arguments);
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to start =
 %%APP_TITLE%% %%PORTVERSION%% since '%%JAVA_HOME%%/%%JAVA_CMD%% -jar =
 %%JAR_FILE%%' in %%APP_HOME%%: ");
 		perror(NULL);
 	} else {
 		printf(" [ DONE ]\n");
 		writePID(file, pid);
 	}
 }
 
 /**
  * Stops the daemon.
  */
 void stop(void) {
 
 	int file;
 	int pid,pid2;
 	char** arguments =3D NULL;
 	int result=3D0;
 	int stdoutLogFile;
 	int stderrLogFile;
 	/* Open and read the PID file */
 	printf(">> Reading PID file (%%PID_FILE%%)...");
 	file =3D openPIDFile();
 	pid =3D readPID(file);
 
 	printf(">> Checking if %%APP_TITLE%% %%PORTVERSION%% is running...");
 
 	/* If there is a PID, see if the process still exists */
 	if (pid !=3D -1) {
 		int result =3D kill(pid, 0);
 		if (result !=3D 0 && errno =3D=3D ESRCH) {
 			ftruncate(file, (off_t) 0);
 			pid =3D -1;
 		}
 	}
 
 	/* If there is no running process, produce an error */
 	if (pid =3D=3D -1) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: %%APP_TITLE%% =
 %%PORTVERSION%% is currently not running.\n");
 		exit(ERR_NOT_RUNNING);
 	}
 	printf(" [ DONE ]\n");
 
 	/* Shutdown tomcat gracefully*/
     printf(">> Shuting down %%APP_TITLE%% %%PORTVERSION%% ...");
 	fflush(NULL);
 	/* Check tomcat and java related files */
 	CheckTomcatJavaEnv();
 	/* Open Log Files*/
 	stdoutLogFile =3D openStdoutLogFile();
 	stderrLogFile =3D openStderrLogFile();
 	pid2 =3D fork();
 	if (pid2 =3D=3D -1) {
 		printf(" [ FAILED ]\n");
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to fork: ");
 		perror(NULL);
 		exit(ERR_FORK_FAILED);
 	}
 
 	if (pid2 =3D=3D 0) {
 		arguments =3D malloc(sizeof(char*) * 6 );
 		arguments[0] =3D "%%JAVA_HOME%%/%%JAVA_CMD%%";
 		arguments[1] =3D "-jar";
 		arguments[2] =3D %%JAVA_ARGS%%;
 		arguments[3] =3D "%%APP_HOME%%/%%JAR_FILE%%";
 		arguments[4] =3D "stop";
 		arguments[5] =3D NULL;
 
 		/* Redirect stdout to log file */
 		dup2(stdoutLogFile, STDOUT_FILENO);
 
 		/* Redirect stderr to log file */
 		dup2(stderrLogFile, STDERR_FILENO);
 
 		/* TODO: Support redirection of both stdout and stderr to the same
 		         file using pipe(2) */
 
 		/* Execute the shutdown command */
 		execv("%%JAVA_HOME%%/%%JAVA_CMD%%", arguments);
 		free(arguments);
 		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to shutdown =
 %%APP_TITLE%% %%PORTVERSION%% since '%%JAVA_HOME%%/%%JAVA_CMD%% -jar =
 %%JAR_FILE%%' in %%APP_HOME%%: ");
 		perror(NULL);
 		/* Terminate the process */
 		killProcess(pid);
 	} else {
 		printf(" [ DONE ]\n");
 		ftruncate(file, (off_t) 0);
 	}
 }
 
 
 /**
  * Restarts the process. If it not currently running, then it will fail.
  */
 void restart(void) {
 	stop();
 	start();
 }
 
 
 ------=_NextPart_000_0007_01C52DA9.EBA59EF0--
 
 
Responsible-Changed-From-To: hq->freebsd-java 
Responsible-Changed-By: hq 
Responsible-Changed-When: Mon Apr 4 20:09:56 GMT 2005 
Responsible-Changed-Why:  
Since there are several PRs on the subject, let assign them all to the same 
person, namely freebsd-java@ 

I'll still handle them but this should help the Java community to keep 
informed. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=75143 
Responsible-Changed-From-To: freebsd-java->lawrance 
Responsible-Changed-By: lawrance 
Responsible-Changed-When: Thu Jan 26 03:21:00 UTC 2006 
Responsible-Changed-Why:  
Handle it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=75143 
State-Changed-From-To: open->closed 
State-Changed-By: lawrance 
State-Changed-When: Tue Feb 7 08:58:55 UTC 2006 
State-Changed-Why:  
tomcatctl has been removed.  Please use the rc scripts 
to control tomcat. 

An rc script was committed to tomcat 4, 4.1, 5, and 5.5 
which allows passing JVM arguments via rc.conf variables. 

Update your tomcat ports, read UPDATING, and refer to the 
head of the rc scripts for details.   

Thanks for your submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=75143 
>Unformatted:
