diff options
author | Herve Quiroz <hq@FreeBSD.org> | 2004-12-22 20:44:23 +0000 |
---|---|---|
committer | Herve Quiroz <hq@FreeBSD.org> | 2004-12-22 20:44:23 +0000 |
commit | f1aa6ae264c2cb227528936995cc0b4b3d521f18 (patch) | |
tree | 9746089c3903a1800cd4e6e7a36234eab49f9033 | |
parent | 5fb6091f09f978cc64d1797317596268b3c41a12 (diff) | |
download | ports-f1aa6ae264c2cb227528936995cc0b4b3d521f18.tar.gz ports-f1aa6ae264c2cb227528936995cc0b4b3d521f18.zip |
Notes
-rw-r--r-- | java/jboss4/Makefile | 14 | ||||
-rw-r--r-- | java/jboss4/files/daemonctl.c | 301 | ||||
-rw-r--r-- | java/jboss4/files/pkg-message | 7 | ||||
-rw-r--r-- | java/jboss4/files/startup.sh | 22 | ||||
-rw-r--r-- | java/jboss5/Makefile | 14 | ||||
-rw-r--r-- | java/jboss5/files/daemonctl.c | 301 | ||||
-rw-r--r-- | java/jboss5/files/pkg-message | 7 | ||||
-rw-r--r-- | java/jboss5/files/startup.sh | 22 |
8 files changed, 338 insertions, 350 deletions
diff --git a/java/jboss4/Makefile b/java/jboss4/Makefile index b41a519d58f9..a459b07906e3 100644 --- a/java/jboss4/Makefile +++ b/java/jboss4/Makefile @@ -7,7 +7,7 @@ PORTNAME= ${APP_TITLE:L} PORTVERSION= 4.0.0 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= java MASTER_SITES= ${MASTER_SITE_SOURCEFORGE} MASTER_SITE_SUBDIR= ${PORTNAME} @@ -52,7 +52,7 @@ JAVA_OPTS= JAVA_CP= bin/run.jar:${JAVA_HOME}/lib/tools.jar JAVA_MAIN= org.jboss.Main DAEMONCTL_DIR= ${FILESDIR} -DAEMONCTL_FILES=daemonctl.c daemonctl.1 startup.sh +DAEMONCTL_FILES=daemonctl.c daemonctl.1 startup.sh pkg-message MAN1= ${CONTROL_SCRIPT_NAME}.1 JBOSSOUTPUT= ${WRKSRC}/build/output/${PORTNAME}-${PORTVERSION} @@ -63,6 +63,8 @@ PLIST_FILES= ${CONTROL_SCRIPT:S,^${PREFIX}/,,} \ ${STDOUT_LOG:S,^${PREFIX}/,,} \ ${STDERR_LOG:S,^${PREFIX}/,,} +PKGMESSAGE= ${WRKDIR}/pkg-message.fmt + .include <bsd.port.pre.mk> do-configure: @@ -86,6 +88,7 @@ do-configure: -e "s|%%JAR_FILE%%|${JAR_FILE}|g;" \ -e "s|%%LOG_DIR%%|${LOG_DIR}|g;" \ -e "s|%%PID_FILE%%|${PID_FILE}|g;" \ + -e "s|%%PKGNAME%%|${PKGNAME}|g;" \ -e "s|%%PORTNAME%%|${PORTNAME}|g;" \ -e "s|%%PORTVERSION%%|${PORTVERSION}|g;" \ -e "s|%%PREFIX%%|${PREFIX}|g;" \ @@ -94,6 +97,7 @@ do-configure: -e "s|%%STDOUT_LOG%%|${STDOUT_LOG}|g;" \ -e "s|%%STOP_TIMEOUT%%|${STOP_TIMEOUT}|g;" \ -e "s|%%USER%%|${USER}|g;" ${DAEMONCTL_FILES}) + @${FMT} -s 80 ${WRKDIR}/pkg-message >${PKGMESSAGE} post-configure: @${ECHO_MSG} "Installation settings:" @@ -141,11 +145,11 @@ post-install: ${SED} -ne 's,^${JBOSSOUTPUT},@dirrm ${APP_HOME:S,${PREFIX}/,,},p' >> ${TMPPLIST} @${ECHO_CMD} "@dirrm ${APP_HOME:S,^${PREFIX}/,,}/log" >> ${TMPPLIST} @${ECHO_CMD} "@dirrm ${APP_HOME:S,^${PREFIX}/,,}" >> ${TMPPLIST} - @${ECHO_MSG} "${PKGNAME} has been installed in ${APP_HOME}." - @${ECHO_MSG} "If a user should be able to use ${CONTROL_SCRIPT_NAME}, put it in the group ${GROUP}." - @${ECHO_MSG} "Use 'man ${CONTROL_SCRIPT_NAME}' for information about starting and stopping ${PORTNAME}." .if ${AUTO_START} == "YES" @${CONTROL_SCRIPT} start || true .endif +.if !defined(BATCH) + @${CAT} ${PKGMESSAGE} +.endif .include <bsd.port.post.mk> diff --git a/java/jboss4/files/daemonctl.c b/java/jboss4/files/daemonctl.c index 619232b272bf..d5f67318b7cf 100644 --- a/java/jboss4/files/daemonctl.c +++ b/java/jboss4/files/daemonctl.c @@ -7,7 +7,7 @@ * Original by Ernst de Haan <znerd@freebsd.org> * www/jakarta-tomcat4/files/daemonctl.c * - * $FreeBSD: /tmp/pcvs/ports/java/jboss4/files/Attic/daemonctl.c,v 1.2 2004-12-18 02:11:35 hq Exp $ + * $FreeBSD: /tmp/pcvs/ports/java/jboss4/files/Attic/daemonctl.c,v 1.3 2004-12-22 20:44:23 hq Exp $ */ #include <assert.h> @@ -27,17 +27,12 @@ #define TRUE 1 #define FALSE 0 -/* 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 @@ -56,18 +51,20 @@ Function declarations. */ static void printUsage (void); -static int openPIDFile (void); -static int readPID (int); -static void writePID (int file, int pid); -static void start (int optcount, char * opts []); +static int readPID (void); +static void writePID (int pid); +static void clearPID (void); +static void start (int javaOpt, char * javaArgs [], int jbossOpt, char * jbossArgs []); static void stop (void); -static void restart (int optcount, char * opts []); +static void restart (int javaOpt, char * javaArgs [], int jbossOpt, char * jbossArgs []); static void logOutput (char *); /* Globals */ static int isQuiet = FALSE; +static char * optQuiet = "-q", /* quiet option */ + * optConfig = "-config"; /* jboss configuration option */ /** * Main function. This function is called when this program is executed. @@ -84,10 +81,9 @@ main ( int argc, char *argv []) { - /* Declare variables, like all other good ANSI C programs do :) */ - int i, jopt; - char *argument, **jargs; + int i, javaOpt, jbossOpt; + char *argument, **javaArgs, **jbossArgs; /* Parse the arguments */ if (argc < 2) @@ -101,26 +97,58 @@ main ( setgid (getegid ()); /* - Build up java-option block. + Build up java and jboss option blocks. */ - jopt = 0; + javaOpt = jbossOpt = 0; for (i = 1; i < argc; i++) { - if (strcmp (argv [i], "-q") == 0) + if (strcmp (argv [i], optQuiet) == 0) + { isQuiet = TRUE; - else if (*argv [i] == '-') - jopt++; + + } else if (strcmp (argv [i], optConfig) == 0) + { + jbossOpt += 2; + if (++i >= argc) + { + printUsage (); + return ERR_ILLEGAL_ARGUMENT; + } + + } else if (*argv [i] == '-') + { + javaOpt++; + } + } + if (javaOpt == 0) + javaArgs = NULL; + else + { + int j = 0; + javaArgs = malloc (sizeof (char *) * javaOpt); + for (i = 0; i < argc; i++) + { + if (strcmp (argv [i], optQuiet) && + strcmp (argv [i], optConfig) && + *argv [i] == '-') + { + javaArgs [j++] = argv [i]; + } + } } - if (jopt == 0) - jargs = NULL; + if (jbossOpt == 0) + jbossArgs = NULL; else { int j = 0; - jargs = malloc (sizeof (char *) * jopt); + jbossArgs = malloc (sizeof (char *) * jbossOpt); for (i = 0; i < argc; i++) { - if (strcmp (argv [i], "-q") && *argv [i] == '-') - jargs [j++] = argv [i]; + if (strcmp (argv [i], optConfig) == 0) + { + jbossArgs [j++] = "-c"; + jbossArgs [j++] = argv [++i]; + } } } @@ -130,14 +158,15 @@ main ( argument = argv [argc - 1]; if (strcmp ("start", argument) == 0) { - start (jopt, jargs); + start (javaOpt, javaArgs, jbossOpt, jbossArgs); } else if (strcmp ("stop", argument) == 0) { stop (); + } else if (strcmp ("restart", argument) == 0) { - restart (jopt, jargs); + restart (javaOpt, javaArgs, jbossOpt, jbossArgs); } else { fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: Illegal argument \"%s\".\n", argument); @@ -145,134 +174,85 @@ main ( exit (ERR_ILLEGAL_ARGUMENT); } - return 0; + return EXIT_SUCCESS; } - /** * Prints usage information to stdout. */ static void printUsage (void) { - printf ("Usage: %%CONTROL_SCRIPT_NAME%% [java-options] {start|stop|restart}\n"); -} - -/** - * 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. - */ -static int -openPIDFile (void) -{ - - int file; - - /* Attempt to open the PID file */ - file = open ("%%PID_FILE%%", O_RDWR); - if (file < 0) { - logOutput (" [ 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; + printf ("Usage: %%CONTROL_SCRIPT_NAME%% [java-options] [-config jbossconfig] {start|stop|restart}\n"); } - /** - * Reads a PID from the specified file. The file is identified by a file - * handle. - * - * @param file - * the file handle. + * Reads a PID from the PID file. * * @return * the PID, or -1 if the file was empty. */ static int -readPID ( - int file) +readPID (void) { - - char *buffer; - int hadNewline = 0; - unsigned int count; - unsigned int i; + FILE * file; int pid; - /* Read the PID file contents */ - buffer = (char *) malloc ((MAX_FILE_SIZE + 1) * sizeof (char)); - count = read (file, buffer, MAX_FILE_SIZE + 1); - if (count > MAX_FILE_SIZE) { + logOutput (">> Reading PID file (%%PID_FILE%%)..."); + file = fopen ("%%PID_FILE%%", "r"); + if (!file) + { logOutput (" [ 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); + perror ("%%CONTROL_SCRIPT_NAME%%: Unable to open %%PID_FILE%% for reading: "); + exit (ERR_PID_FILE_NOT_FOUND); } + if (fscanf (file, "%d", &pid) < 1) + pid = -1; + fclose (file); - /* Convert the bytes to a number */ - pid = 0; - for (i=0; i<count; i++) { - char c = buffer[i]; - if (c >= '0' && c <= '9') { - char digit = c - '0'; - pid *= 10; - pid += digit; - } else if (i == (count - 1) && c == '\n') { - /* XXX: Ignore a newline at the end of the file */ - hadNewline = 1; - } else { - logOutput (" [ 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); - } - } logOutput (" [ DONE ]\n"); - - if (count == 0 || (count == 1 && hadNewline == 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. */ static void writePID ( - int file, int pid) { - - char *buffer; - int nbytes; - - /* Check preconditions */ - assert (file > 0); - assert (pid > 0); + FILE * file; logOutput (">> Writing PID file..."); + file = fopen ("%%PID_FILE%%", "w"); + if (!file) + { + logOutput (" [ FAILED ]\n"); + perror ("%%CONTROL_SCRIPT_NAME%%: Unable to open %%PID_FILE%% for writing: "); + exit (ERR_PID_FILE_NOT_FOUND); + } + fprintf (file, "%d\n", pid); + fclose (file); - lseek (file, (off_t) 0, SEEK_SET); - ftruncate (file, (off_t) 0); - nbytes = asprintf (&buffer, "%d\n", pid); - write (file, buffer, nbytes); logOutput (" [ DONE ]\n"); } +/** + Truncate the PID file. + */ +static void +clearPID (void) +{ + if (truncate ("%%PID_FILE%%", 0) != 0) + { + perror ("%%CONTROL_SCRIPT_NAME%%: Unable to clear %%PID_FILE%%: "); + exit (ERR_PID_FILE_NOT_FOUND); + } +} /** * Checks if the specified process is running. @@ -287,7 +267,6 @@ static int existsProcess ( int pid) { - int result; /* Check preconditions */ @@ -297,14 +276,9 @@ existsProcess ( result = kill (pid, 0); /* If the result is 0, then the process exists */ - if (result == 0) { - return 1; - } else { - return 0; - } + return result == 0; } - /** * Kills the process identified by the specified ID. * @@ -315,7 +289,6 @@ static void killProcess ( int pid) { - int result; unsigned int waited; unsigned int forced; @@ -347,13 +320,13 @@ killProcess ( /* If the process still exists, then have no mercy and kill it */ forced = 0; - if (result == 1) { - + if (result == 1) + { /* Force the process to die */ result = kill (pid, SIGKILL); if (result == 0) { forced = 1; - logOutput (" [ DONE ]\n"); + logOutput (" [ KILLED ]\n"); fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: Process %d did not terminate within %%STOP_TIMEOUT%% sec. Killed.\n", pid); } else if (result != ESRCH) { logOutput (" [ FAILED ]\n"); @@ -373,27 +346,28 @@ killProcess ( */ static void start ( - int optcount, - char * opts []) + int javaOpt, + char * javaArgs [], + int jbossOpt, + char * jbossArgs []) { - int file; + int i, argc; + char ** argv; int pid; int result; int stdoutLogFile; int stderrLogFile; struct stat sb; - /* Open and read the PID file */ - logOutput (">> Reading PID file (%%PID_FILE%%)..."); - file = openPIDFile (); - pid = readPID (file); + pid = readPID (); logOutput (">> Starting %%APP_TITLE%% %%PORTVERSION%%..."); - if (pid != -1) { - + if (pid != -1) + { /* Check if the process actually exists */ result = existsProcess (pid); - if (result == 1) { + if (result == 1) + { logOutput (" [ FAILED ]\n"); fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: %%APP_TITLE%% %%PORTVERSION%% is already running, PID is %d.\n", pid); exit (ERR_ALREADY_RUNNING); @@ -474,19 +448,16 @@ start ( lseek (stderrLogFile, (off_t) 0, SEEK_END); /* Split this process in two */ - pid = fork (); - if (pid == -1) { + switch (pid = fork ()) + { + case -1: logOutput (" [ FAILED ]\n"); fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to fork: "); perror (NULL); exit (ERR_FORK_FAILED); - } - - if (pid == 0) - { - int i, argc; - char **argv; + break; + case 0: /* Redirect stdout to log file */ dup2 (stdoutLogFile, STDOUT_FILENO); @@ -494,29 +465,31 @@ start ( dup2 (stderrLogFile, STDERR_FILENO); /* TODO: Support redirection of both stdout and stderr to the same - file using pipe (2) */ + file using pipe (2) */ /* - Build the argument vector, with the java-options if any. + Build the argument vector, with the java/jboss options if any. */ - argv = malloc (sizeof (char *) * (optcount + 5)); + argv = malloc (sizeof (char *) * (javaOpt + jbossOpt + 5)); argc = 0; argv [argc++] = "%%JAVA%%"; - for (i = 0; i < optcount; i++) - argv [argc++] = opts [i]; + for (i = 0; i < javaOpt; i++) + argv [argc++] = javaArgs [i]; argv [argc++] = "-cp"; argv [argc++] = "%%JAVA_CP%%"; argv [argc++] = "%%JAVA_MAIN%%"; + for (i = 0; i < jbossOpt; i++) + argv [argc++] = jbossArgs [i]; argv [argc++] = NULL; /* Execute the command */ execv (argv [0], argv); - perror (NULL); - } else - { + break; + + default: logOutput (" [ DONE ]\n"); - writePID (file, pid); + writePID (pid); } } @@ -526,28 +499,26 @@ start ( static void stop (void) { - - int file; int pid; - /* Open and read the PID file */ - logOutput (">> Reading PID file (%%PID_FILE%%)..."); - file = openPIDFile (); - pid = readPID (file); + pid = readPID (); logOutput (">> Checking if %%APP_TITLE%% %%PORTVERSION%% is running..."); /* If there is a PID, see if the process still exists */ - if (pid != -1) { + if (pid != -1) + { int result = kill (pid, 0); - if (result != 0 && errno == ESRCH) { - ftruncate (file, (off_t) 0); + if (result != 0 && errno == ESRCH) + { + clearPID (); pid = -1; } } /* If there is no running process, produce an error */ - if (pid == -1) { + if (pid == -1) + { logOutput (" [ FAILED ]\n"); fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: %%APP_TITLE%% %%PORTVERSION%% is currently not running.\n"); exit (ERR_NOT_RUNNING); @@ -556,9 +527,7 @@ stop (void) /* Terminate the process */ killProcess (pid); - - /* Clear the PID file */ - ftruncate (file, (off_t) 0); + clearPID (); } @@ -567,11 +536,13 @@ stop (void) */ static void restart ( - int optcount, - char * opts []) + int javaOpt, + char * javaArgs [], + int jbossOpt, + char * jbossArgs []) { stop (); - start (optcount, opts); + start (javaOpt, javaArgs, jbossOpt, jbossArgs); } /** diff --git a/java/jboss4/files/pkg-message b/java/jboss4/files/pkg-message new file mode 100644 index 000000000000..e48411f3028c --- /dev/null +++ b/java/jboss4/files/pkg-message @@ -0,0 +1,7 @@ +%%PKGNAME%% has been installed in %%APP_HOME%%. + +If a user should be able to use %%CONTROL_SCRIPT_NAME%%, put it in the group '%%GROUP%%'. + +Use 'man %%CONTROL_SCRIPT_NAME%%' for information about starting and stopping %%APP_TITLE%%. + +To run the %%APP_TITLE%% server from startup, add %%APP_SHORTNAME%%_enable="YES" in your /etc/rc.conf. Extra options can be found in the startup script. diff --git a/java/jboss4/files/startup.sh b/java/jboss4/files/startup.sh index c6690cafd0a6..bea0ed4d6174 100644 --- a/java/jboss4/files/startup.sh +++ b/java/jboss4/files/startup.sh @@ -1,10 +1,8 @@ #!/bin/sh -# -*- mode: Fundamental; tab-width: 4; -*- -# ex:ts=4 # # %%APP_TITLE%% startup script. # -# $FreeBSD: /tmp/pcvs/ports/java/jboss4/files/Attic/startup.sh,v 1.2 2004-12-18 02:11:35 hq Exp $ +# $FreeBSD: /tmp/pcvs/ports/java/jboss4/files/Attic/startup.sh,v 1.3 2004-12-22 20:44:23 hq Exp $ # # PROVIDE: %%APP_SHORTNAME%% @@ -15,6 +13,8 @@ # Set it to "YES" to enable %%APP_SHORTNAME%% # %%APP_SHORTNAME%%_flags (str): Set to "-server" by default. # Extra JVM flags. +# %%APP_SHORTNAME%%_config (str): Set to "" by default +# JBoss server config, eg {all|default|minimal|standard} # . %%RC_SUBR%% @@ -28,19 +28,31 @@ procname="%%JAVA%%" [ -z "$%%APP_SHORTNAME%%_enable" ] && %%APP_SHORTNAME%%_enable="NO" [ -z "$%%APP_SHORTNAME%%_flags" ] && %%APP_SHORTNAME%%_flags="-server" +[ -z "$%%APP_SHORTNAME%%_config" ] && %%APP_SHORTNAME%%_config="" %%APP_SHORTNAME%%_start () { checkyesno %%APP_SHORTNAME%%_enable && - %%CONTROL_SCRIPT%% -q ${%%APP_SHORTNAME%%_flags} start && + { + if [ ! -f ${pidfile} ] + then + touch ${pidfile} + chown %%USER%%:%%GROUP%% ${pidfile} + fi + + %%CONTROL_SCRIPT%% -q ${%%APP_SHORTNAME%%_flags} ${%%APP_SHORTNAME%%_configflag} ${%%APP_SHORTNAME%%_config} start && echo -n " %%APP_SHORTNAME%%" + } } %%APP_SHORTNAME%%_restart () { checkyesno %%APP_SHORTNAME%%_enable && - %%CONTROL_SCRIPT%% -q ${%%APP_SHORTNAME%%_flags} restart + %%CONTROL_SCRIPT%% -q ${%%APP_SHORTNAME%%_flags} ${%%APP_SHORTNAME%%_configflag} ${%%APP_SHORTNAME%%_config} restart } load_rc_config $name + +[ -n "${%%APP_SHORTNAME%%_config}" ] && %%APP_SHORTNAME%%_configflag="-config" + run_rc_command "$1" diff --git a/java/jboss5/Makefile b/java/jboss5/Makefile index b41a519d58f9..a459b07906e3 100644 --- a/java/jboss5/Makefile +++ b/java/jboss5/Makefile @@ -7,7 +7,7 @@ PORTNAME= ${APP_TITLE:L} PORTVERSION= 4.0.0 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= java MASTER_SITES= ${MASTER_SITE_SOURCEFORGE} MASTER_SITE_SUBDIR= ${PORTNAME} @@ -52,7 +52,7 @@ JAVA_OPTS= JAVA_CP= bin/run.jar:${JAVA_HOME}/lib/tools.jar JAVA_MAIN= org.jboss.Main DAEMONCTL_DIR= ${FILESDIR} -DAEMONCTL_FILES=daemonctl.c daemonctl.1 startup.sh +DAEMONCTL_FILES=daemonctl.c daemonctl.1 startup.sh pkg-message MAN1= ${CONTROL_SCRIPT_NAME}.1 JBOSSOUTPUT= ${WRKSRC}/build/output/${PORTNAME}-${PORTVERSION} @@ -63,6 +63,8 @@ PLIST_FILES= ${CONTROL_SCRIPT:S,^${PREFIX}/,,} \ ${STDOUT_LOG:S,^${PREFIX}/,,} \ ${STDERR_LOG:S,^${PREFIX}/,,} +PKGMESSAGE= ${WRKDIR}/pkg-message.fmt + .include <bsd.port.pre.mk> do-configure: @@ -86,6 +88,7 @@ do-configure: -e "s|%%JAR_FILE%%|${JAR_FILE}|g;" \ -e "s|%%LOG_DIR%%|${LOG_DIR}|g;" \ -e "s|%%PID_FILE%%|${PID_FILE}|g;" \ + -e "s|%%PKGNAME%%|${PKGNAME}|g;" \ -e "s|%%PORTNAME%%|${PORTNAME}|g;" \ -e "s|%%PORTVERSION%%|${PORTVERSION}|g;" \ -e "s|%%PREFIX%%|${PREFIX}|g;" \ @@ -94,6 +97,7 @@ do-configure: -e "s|%%STDOUT_LOG%%|${STDOUT_LOG}|g;" \ -e "s|%%STOP_TIMEOUT%%|${STOP_TIMEOUT}|g;" \ -e "s|%%USER%%|${USER}|g;" ${DAEMONCTL_FILES}) + @${FMT} -s 80 ${WRKDIR}/pkg-message >${PKGMESSAGE} post-configure: @${ECHO_MSG} "Installation settings:" @@ -141,11 +145,11 @@ post-install: ${SED} -ne 's,^${JBOSSOUTPUT},@dirrm ${APP_HOME:S,${PREFIX}/,,},p' >> ${TMPPLIST} @${ECHO_CMD} "@dirrm ${APP_HOME:S,^${PREFIX}/,,}/log" >> ${TMPPLIST} @${ECHO_CMD} "@dirrm ${APP_HOME:S,^${PREFIX}/,,}" >> ${TMPPLIST} - @${ECHO_MSG} "${PKGNAME} has been installed in ${APP_HOME}." - @${ECHO_MSG} "If a user should be able to use ${CONTROL_SCRIPT_NAME}, put it in the group ${GROUP}." - @${ECHO_MSG} "Use 'man ${CONTROL_SCRIPT_NAME}' for information about starting and stopping ${PORTNAME}." .if ${AUTO_START} == "YES" @${CONTROL_SCRIPT} start || true .endif +.if !defined(BATCH) + @${CAT} ${PKGMESSAGE} +.endif .include <bsd.port.post.mk> diff --git a/java/jboss5/files/daemonctl.c b/java/jboss5/files/daemonctl.c index 8df4f6b05833..215d5bcd50c3 100644 --- a/java/jboss5/files/daemonctl.c +++ b/java/jboss5/files/daemonctl.c @@ -7,7 +7,7 @@ * Original by Ernst de Haan <znerd@freebsd.org> * www/jakarta-tomcat4/files/daemonctl.c * - * $FreeBSD: /tmp/pcvs/ports/java/jboss5/files/Attic/daemonctl.c,v 1.2 2004-12-18 02:11:35 hq Exp $ + * $FreeBSD: /tmp/pcvs/ports/java/jboss5/files/Attic/daemonctl.c,v 1.3 2004-12-22 20:44:23 hq Exp $ */ #include <assert.h> @@ -27,17 +27,12 @@ #define TRUE 1 #define FALSE 0 -/* 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 @@ -56,18 +51,20 @@ Function declarations. */ static void printUsage (void); -static int openPIDFile (void); -static int readPID (int); -static void writePID (int file, int pid); -static void start (int optcount, char * opts []); +static int readPID (void); +static void writePID (int pid); +static void clearPID (void); +static void start (int javaOpt, char * javaArgs [], int jbossOpt, char * jbossArgs []); static void stop (void); -static void restart (int optcount, char * opts []); +static void restart (int javaOpt, char * javaArgs [], int jbossOpt, char * jbossArgs []); static void logOutput (char *); /* Globals */ static int isQuiet = FALSE; +static char * optQuiet = "-q", /* quiet option */ + * optConfig = "-config"; /* jboss configuration option */ /** * Main function. This function is called when this program is executed. @@ -84,10 +81,9 @@ main ( int argc, char *argv []) { - /* Declare variables, like all other good ANSI C programs do :) */ - int i, jopt; - char *argument, **jargs; + int i, javaOpt, jbossOpt; + char *argument, **javaArgs, **jbossArgs; /* Parse the arguments */ if (argc < 2) @@ -101,26 +97,58 @@ main ( setgid (getegid ()); /* - Build up java-option block. + Build up java and jboss option blocks. */ - jopt = 0; + javaOpt = jbossOpt = 0; for (i = 1; i < argc; i++) { - if (strcmp (argv [i], "-q") == 0) + if (strcmp (argv [i], optQuiet) == 0) + { isQuiet = TRUE; - else if (*argv [i] == '-') - jopt++; + + } else if (strcmp (argv [i], optConfig) == 0) + { + jbossOpt += 2; + if (++i >= argc) + { + printUsage (); + return ERR_ILLEGAL_ARGUMENT; + } + + } else if (*argv [i] == '-') + { + javaOpt++; + } + } + if (javaOpt == 0) + javaArgs = NULL; + else + { + int j = 0; + javaArgs = malloc (sizeof (char *) * javaOpt); + for (i = 0; i < argc; i++) + { + if (strcmp (argv [i], optQuiet) && + strcmp (argv [i], optConfig) && + *argv [i] == '-') + { + javaArgs [j++] = argv [i]; + } + } } - if (jopt == 0) - jargs = NULL; + if (jbossOpt == 0) + jbossArgs = NULL; else { int j = 0; - jargs = malloc (sizeof (char *) * jopt); + jbossArgs = malloc (sizeof (char *) * jbossOpt); for (i = 0; i < argc; i++) { - if (strcmp (argv [i], "-q") && *argv [i] == '-') - jargs [j++] = argv [i]; + if (strcmp (argv [i], optConfig) == 0) + { + jbossArgs [j++] = "-c"; + jbossArgs [j++] = argv [++i]; + } } } @@ -130,14 +158,15 @@ main ( argument = argv [argc - 1]; if (strcmp ("start", argument) == 0) { - start (jopt, jargs); + start (javaOpt, javaArgs, jbossOpt, jbossArgs); } else if (strcmp ("stop", argument) == 0) { stop (); + } else if (strcmp ("restart", argument) == 0) { - restart (jopt, jargs); + restart (javaOpt, javaArgs, jbossOpt, jbossArgs); } else { fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: Illegal argument \"%s\".\n", argument); @@ -145,134 +174,85 @@ main ( exit (ERR_ILLEGAL_ARGUMENT); } - return 0; + return EXIT_SUCCESS; } - /** * Prints usage information to stdout. */ static void printUsage (void) { - printf ("Usage: %%CONTROL_SCRIPT_NAME%% [java-options] {start|stop|restart}\n"); -} - -/** - * 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. - */ -static int -openPIDFile (void) -{ - - int file; - - /* Attempt to open the PID file */ - file = open ("%%PID_FILE%%", O_RDWR); - if (file < 0) { - logOutput (" [ 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; + printf ("Usage: %%CONTROL_SCRIPT_NAME%% [java-options] [-config jbossconfig] {start|stop|restart}\n"); } - /** - * Reads a PID from the specified file. The file is identified by a file - * handle. - * - * @param file - * the file handle. + * Reads a PID from the PID file. * * @return * the PID, or -1 if the file was empty. */ static int -readPID ( - int file) +readPID (void) { - - char *buffer; - int hadNewline = 0; - unsigned int count; - unsigned int i; + FILE * file; int pid; - /* Read the PID file contents */ - buffer = (char *) malloc ((MAX_FILE_SIZE + 1) * sizeof (char)); - count = read (file, buffer, MAX_FILE_SIZE + 1); - if (count > MAX_FILE_SIZE) { + logOutput (">> Reading PID file (%%PID_FILE%%)..."); + file = fopen ("%%PID_FILE%%", "r"); + if (!file) + { logOutput (" [ 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); + perror ("%%CONTROL_SCRIPT_NAME%%: Unable to open %%PID_FILE%% for reading: "); + exit (ERR_PID_FILE_NOT_FOUND); } + if (fscanf (file, "%d", &pid) < 1) + pid = -1; + fclose (file); - /* Convert the bytes to a number */ - pid = 0; - for (i=0; i<count; i++) { - char c = buffer[i]; - if (c >= '0' && c <= '9') { - char digit = c - '0'; - pid *= 10; - pid += digit; - } else if (i == (count - 1) && c == '\n') { - /* XXX: Ignore a newline at the end of the file */ - hadNewline = 1; - } else { - logOutput (" [ 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); - } - } logOutput (" [ DONE ]\n"); - - if (count == 0 || (count == 1 && hadNewline == 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. */ static void writePID ( - int file, int pid) { - - char *buffer; - int nbytes; - - /* Check preconditions */ - assert (file > 0); - assert (pid > 0); + FILE * file; logOutput (">> Writing PID file..."); + file = fopen ("%%PID_FILE%%", "w"); + if (!file) + { + logOutput (" [ FAILED ]\n"); + perror ("%%CONTROL_SCRIPT_NAME%%: Unable to open %%PID_FILE%% for writing: "); + exit (ERR_PID_FILE_NOT_FOUND); + } + fprintf (file, "%d\n", pid); + fclose (file); - lseek (file, (off_t) 0, SEEK_SET); - ftruncate (file, (off_t) 0); - nbytes = asprintf (&buffer, "%d\n", pid); - write (file, buffer, nbytes); logOutput (" [ DONE ]\n"); } +/** + Truncate the PID file. + */ +static void +clearPID (void) +{ + if (truncate ("%%PID_FILE%%", 0) != 0) + { + perror ("%%CONTROL_SCRIPT_NAME%%: Unable to clear %%PID_FILE%%: "); + exit (ERR_PID_FILE_NOT_FOUND); + } +} /** * Checks if the specified process is running. @@ -287,7 +267,6 @@ static int existsProcess ( int pid) { - int result; /* Check preconditions */ @@ -297,14 +276,9 @@ existsProcess ( result = kill (pid, 0); /* If the result is 0, then the process exists */ - if (result == 0) { - return 1; - } else { - return 0; - } + return result == 0; } - /** * Kills the process identified by the specified ID. * @@ -315,7 +289,6 @@ static void killProcess ( int pid) { - int result; unsigned int waited; unsigned int forced; @@ -347,13 +320,13 @@ killProcess ( /* If the process still exists, then have no mercy and kill it */ forced = 0; - if (result == 1) { - + if (result == 1) + { /* Force the process to die */ result = kill (pid, SIGKILL); if (result == 0) { forced = 1; - logOutput (" [ DONE ]\n"); + logOutput (" [ KILLED ]\n"); fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: Process %d did not terminate within %%STOP_TIMEOUT%% sec. Killed.\n", pid); } else if (result != ESRCH) { logOutput (" [ FAILED ]\n"); @@ -373,27 +346,28 @@ killProcess ( */ static void start ( - int optcount, - char * opts []) + int javaOpt, + char * javaArgs [], + int jbossOpt, + char * jbossArgs []) { - int file; + int i, argc; + char ** argv; int pid; int result; int stdoutLogFile; int stderrLogFile; struct stat sb; - /* Open and read the PID file */ - logOutput (">> Reading PID file (%%PID_FILE%%)..."); - file = openPIDFile (); - pid = readPID (file); + pid = readPID (); logOutput (">> Starting %%APP_TITLE%% %%PORTVERSION%%..."); - if (pid != -1) { - + if (pid != -1) + { /* Check if the process actually exists */ result = existsProcess (pid); - if (result == 1) { + if (result == 1) + { logOutput (" [ FAILED ]\n"); fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: %%APP_TITLE%% %%PORTVERSION%% is already running, PID is %d.\n", pid); exit (ERR_ALREADY_RUNNING); @@ -474,19 +448,16 @@ start ( lseek (stderrLogFile, (off_t) 0, SEEK_END); /* Split this process in two */ - pid = fork (); - if (pid == -1) { + switch (pid = fork ()) + { + case -1: logOutput (" [ FAILED ]\n"); fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to fork: "); perror (NULL); exit (ERR_FORK_FAILED); - } - - if (pid == 0) - { - int i, argc; - char **argv; + break; + case 0: /* Redirect stdout to log file */ dup2 (stdoutLogFile, STDOUT_FILENO); @@ -494,29 +465,31 @@ start ( dup2 (stderrLogFile, STDERR_FILENO); /* TODO: Support redirection of both stdout and stderr to the same - file using pipe (2) */ + file using pipe (2) */ /* - Build the argument vector, with the java-options if any. + Build the argument vector, with the java/jboss options if any. */ - argv = malloc (sizeof (char *) * (optcount + 5)); + argv = malloc (sizeof (char *) * (javaOpt + jbossOpt + 5)); argc = 0; argv [argc++] = "%%JAVA%%"; - for (i = 0; i < optcount; i++) - argv [argc++] = opts [i]; + for (i = 0; i < javaOpt; i++) + argv [argc++] = javaArgs [i]; argv [argc++] = "-cp"; argv [argc++] = "%%JAVA_CP%%"; argv [argc++] = "%%JAVA_MAIN%%"; + for (i = 0; i < jbossOpt; i++) + argv [argc++] = jbossArgs [i]; argv [argc++] = NULL; /* Execute the command */ execv (argv [0], argv); - perror (NULL); - } else - { + break; + + default: logOutput (" [ DONE ]\n"); - writePID (file, pid); + writePID (pid); } } @@ -526,28 +499,26 @@ start ( static void stop (void) { - - int file; int pid; - /* Open and read the PID file */ - logOutput (">> Reading PID file (%%PID_FILE%%)..."); - file = openPIDFile (); - pid = readPID (file); + pid = readPID (); logOutput (">> Checking if %%APP_TITLE%% %%PORTVERSION%% is running..."); /* If there is a PID, see if the process still exists */ - if (pid != -1) { + if (pid != -1) + { int result = kill (pid, 0); - if (result != 0 && errno == ESRCH) { - ftruncate (file, (off_t) 0); + if (result != 0 && errno == ESRCH) + { + clearPID (); pid = -1; } } /* If there is no running process, produce an error */ - if (pid == -1) { + if (pid == -1) + { logOutput (" [ FAILED ]\n"); fprintf (stderr, "%%CONTROL_SCRIPT_NAME%%: %%APP_TITLE%% %%PORTVERSION%% is currently not running.\n"); exit (ERR_NOT_RUNNING); @@ -556,9 +527,7 @@ stop (void) /* Terminate the process */ killProcess (pid); - - /* Clear the PID file */ - ftruncate (file, (off_t) 0); + clearPID (); } @@ -567,11 +536,13 @@ stop (void) */ static void restart ( - int optcount, - char * opts []) + int javaOpt, + char * javaArgs [], + int jbossOpt, + char * jbossArgs []) { stop (); - start (optcount, opts); + start (javaOpt, javaArgs, jbossOpt, jbossArgs); } /** diff --git a/java/jboss5/files/pkg-message b/java/jboss5/files/pkg-message new file mode 100644 index 000000000000..e48411f3028c --- /dev/null +++ b/java/jboss5/files/pkg-message @@ -0,0 +1,7 @@ +%%PKGNAME%% has been installed in %%APP_HOME%%. + +If a user should be able to use %%CONTROL_SCRIPT_NAME%%, put it in the group '%%GROUP%%'. + +Use 'man %%CONTROL_SCRIPT_NAME%%' for information about starting and stopping %%APP_TITLE%%. + +To run the %%APP_TITLE%% server from startup, add %%APP_SHORTNAME%%_enable="YES" in your /etc/rc.conf. Extra options can be found in the startup script. diff --git a/java/jboss5/files/startup.sh b/java/jboss5/files/startup.sh index b4c87c7ff76f..9ee364814b6b 100644 --- a/java/jboss5/files/startup.sh +++ b/java/jboss5/files/startup.sh @@ -1,10 +1,8 @@ #!/bin/sh -# -*- mode: Fundamental; tab-width: 4; -*- -# ex:ts=4 # # %%APP_TITLE%% startup script. # -# $FreeBSD: /tmp/pcvs/ports/java/jboss5/files/Attic/startup.sh,v 1.2 2004-12-18 02:11:35 hq Exp $ +# $FreeBSD: /tmp/pcvs/ports/java/jboss5/files/Attic/startup.sh,v 1.3 2004-12-22 20:44:23 hq Exp $ # # PROVIDE: %%APP_SHORTNAME%% @@ -15,6 +13,8 @@ # Set it to "YES" to enable %%APP_SHORTNAME%% # %%APP_SHORTNAME%%_flags (str): Set to "-server" by default. # Extra JVM flags. +# %%APP_SHORTNAME%%_config (str): Set to "" by default +# JBoss server config, eg {all|default|minimal|standard} # . %%RC_SUBR%% @@ -28,19 +28,31 @@ procname="%%JAVA%%" [ -z "$%%APP_SHORTNAME%%_enable" ] && %%APP_SHORTNAME%%_enable="NO" [ -z "$%%APP_SHORTNAME%%_flags" ] && %%APP_SHORTNAME%%_flags="-server" +[ -z "$%%APP_SHORTNAME%%_config" ] && %%APP_SHORTNAME%%_config="" %%APP_SHORTNAME%%_start () { checkyesno %%APP_SHORTNAME%%_enable && - %%CONTROL_SCRIPT%% -q ${%%APP_SHORTNAME%%_flags} start && + { + if [ ! -f ${pidfile} ] + then + touch ${pidfile} + chown %%USER%%:%%GROUP%% ${pidfile} + fi + + %%CONTROL_SCRIPT%% -q ${%%APP_SHORTNAME%%_flags} ${%%APP_SHORTNAME%%_configflag} ${%%APP_SHORTNAME%%_config} start && echo -n " %%APP_SHORTNAME%%" + } } %%APP_SHORTNAME%%_restart () { checkyesno %%APP_SHORTNAME%%_enable && - %%CONTROL_SCRIPT%% -q ${%%APP_SHORTNAME%%_flags} restart + %%CONTROL_SCRIPT%% -q ${%%APP_SHORTNAME%%_flags} ${%%APP_SHORTNAME%%_configflag} ${%%APP_SHORTNAME%%_config} restart } load_rc_config $name + +[ -n "${%%APP_SHORTNAME%%_config}" ] && %%APP_SHORTNAME%%_configflag="-config" + run_rc_command "$1" |