head	1.5;
access;
symbols
	RELEASE_8_3_0:1.4
	RELEASE_9_0_0:1.4
	RELEASE_7_4_0:1.4
	RELEASE_8_2_0:1.4
	RELEASE_6_EOL:1.4
	RELEASE_8_1_0:1.4
	RELEASE_7_3_0:1.4
	RELEASE_8_0_0:1.4
	RELEASE_7_2_0:1.4
	RELEASE_7_1_0:1.4
	RELEASE_6_4_0:1.4
	RELEASE_5_EOL:1.4
	RELEASE_7_0_0:1.4
	RELEASE_6_3_0:1.4
	PRE_XORG_7:1.4
	RELEASE_4_EOL:1.4
	RELEASE_6_2_0:1.3
	RELEASE_6_1_0:1.3
	RELEASE_5_5_0:1.3
	RELEASE_6_0_0:1.2
	RELEASE_5_4_0:1.1;
locks; strict;
comment	@# @;


1.5
date	2012.04.10.19.24.12;	author jgh;	state dead;
branches;
next	1.4;

1.4
date	2006.12.16.02.14.26;	author rafan;	state Exp;
branches;
next	1.3;

1.3
date	2005.12.21.20.55.50;	author hq;	state Exp;
branches;
next	1.2;

1.2
date	2005.04.15.00.30.48;	author hq;	state Exp;
branches;
next	1.1;

1.1
date	2005.02.24.22.27.53;	author hq;	state Exp;
branches;
next	;


desc
@@


1.5
log
@- port has expired, and is no longer supported upstream

2012-04-10  unsupported upstream, consider www/resin3

PR: ports/165867
Approved by:	maintainer, boris@@tagnet.ru
@
text
@#! %%PYTHON_CMD%%

################################################################################
# Author:        Jean-Baptiste Quenot <jb.quenot@@caraldi.com>
# Purpose:       Manage resin pid file and log files
# Date Created:  2005-01-21 15:43:19
# Revision:      $FreeBSD: ports/www/resin2/files/resinctl,v 1.4 2006/12/16 02:14:26 rafan Exp $
################################################################################
# Copyright (c) 2004, Jean-Baptiste Quenot <jb.quenot@@caraldi.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
#   list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
# * The name of the contributors may not be used to endorse or promote products
#   derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
#
# Files handled by this script (pid file, log files) must reside in a writable
# directory, ie the directory must be owned by the user running the program.

import sys, os, signal, time, stat, re

def classpath():
    classpath = []
    resin_libdir = APP_HOME + "/lib"
    java_libdir = os.environ['JAVA_HOME'] + "/lib"
    for libdir in [resin_libdir, java_libdir]:
        for file in os.listdir(libdir):
            if re.search("\.jar$", file):
                classpath.append(libdir + "/" + file)
    return ':'.join(classpath)

#    -socketwait 12345
#    -stdout $APP_HOME/log/stdout.log
#    -stderr $APP_HOME/log/stderr.log

def readProcessId():
    f = open(PID_FILE, 'r')
    pid = int(f.readline())
    f.close()
    return pid

def isProgramRunning(pid):
    # Send a dummy signal to the process.  If it died, an exception is
    # thrown
    try:
        os.kill(pid, signal.SIGCONT)
        return 1
    except OSError:
        return 0

def usage():
    print >> sys.stderr, "Usage: %s {start|stop|restart}" % sys.argv[0]

def start():
    cwd = os.getcwd()
    if os.path.exists(PID_FILE):
        # Read the process id
        pid = readProcessId()

        if isProgramRunning(pid):
            print >> sys.stderr, '%s already started' % APP_NAME
            sys.exit(3)

    if not(os.path.exists(COMMAND)):
        print >> sys.stderr, '%s cannot be found' % COMMAND
        sys.exit(3)

    # Append program output to a log file
    l = open(LOG_FILE, 'a')
    orig_stderr = os.dup(sys.stderr.fileno())
    os.dup2(l.fileno(), sys.stdout.fileno())
    os.dup2(l.fileno(), sys.stderr.fileno())

    finfo = os.stat(COMMAND)[stat.ST_MODE]
    executable = stat.S_IMODE(finfo) & 0111
    if not(executable):
        sys.stderr = os.fdopen(orig_stderr, 'w')
        print >> sys.stderr, 'Cannot run %s, execute bit is missing' % COMMAND
        sys.exit(5)

    if APP_HOME:
        # Change current directory to APP_HOME
        os.chdir(APP_HOME)

    # Start program in the background
    pid = os.spawnv(os.P_NOWAIT, COMMAND, ARGS)

    # Wait a little
    time.sleep(.4)
    (status_pid, status) = os.waitpid(pid, os.WNOHANG)

    # Check program exit status, if available
    if status_pid != 0 and os.WIFEXITED(status):
        sys.stderr = os.fdopen(orig_stderr, 'w')
        print >> sys.stderr, 'Could not start %s.  Check %s for errors.' % (APP_NAME, LOG_FILE)
        sys.exit(2)

    # It's alive, so write down the process id
    os.chdir(cwd)
    f = open(PID_FILE, 'w')
    print >> f, pid
    f.close()

def warnNotRunning():
    if sys.argv[1] == "stop":
        print >> sys.stderr, '%s is not running' % APP_NAME
    else:
        print >> sys.stderr, 'Warning: %s was not running' % APP_NAME

def cleanup():
    os.unlink(PID_FILE)

def stop():
    if os.path.exists(PID_FILE):
        # Read the process id
        pid = readProcessId()
    else:
        warnNotRunning()
        return

    if not(isProgramRunning(pid)):
        warnNotRunning()
        cleanup()
        return

    # Terminate program
    os.kill(pid, signal.SIGTERM)

    while isProgramRunning(pid):
        time.sleep(.1)

    cleanup()

if __name__ == '__main__':
    LOG_FILE = "%%LOG_FILE%%"
    APP_NAME = "%%APP_NAME%%"
    APP_HOME = "%%APP_HOME%%"
    PID_FILE = "%%PID_FILE%%"
    COMMAND = "%%PREFIX%%/bin/java"
    ARGS = [COMMAND]

    ARGS += sys.argv[1:-1]

    ARGS += [
        "-Dresin.home=%%APP_HOME%%",
        "com.caucho.server.http.HttpServer",
        "-conf", "%%PREFIX%%/etc/%%APP_NAME%%.xml"
        ]

    os.environ['CLASSPATH'] = classpath()
    os.environ['PATH'] = "%%LOCALBASE%%/bin:/usr/bin:/bin"

    if len(sys.argv) < 2:
        usage()
        sys.exit(1)

    if sys.argv[-1] == "start":
        start()

    elif sys.argv[-1] == "stop":
        stop()

    elif sys.argv[-1] == "restart":
        stop()
        start()

    else:
        usage()
        sys.exit(1)
@


1.4
log
@- Fix build on 64-bit arch

Keep sync with www/resin3:

- A new option can be set in rc.conf to specify Java version to be used:
  resin2_java_version
- Set REQUIRE and KEYWORD in rc.d script
- Fix faststart in rc.d script
- Update maintainer's email

PR:		ports/106793
Submitted by:	Jean-Baptiste Quenot <jb.quenot at caraldi.com> (maintainer)
@
text
@d7 1
a7 1
# Revision:      $FreeBSD: ports/www/resin2/files/resinctl,v 1.3 2005/12/21 20:55:50 hq Exp $
@


1.3
log
@- Update to 2.1.17
- Add support for OpenSSL
- Handle resin2_flags to pass JVM options in rc(8)
- Fix the port so that it may be built (and cleaned) correctly as a user

PR:		90489
Submitted by:	maintainer
@
text
@d7 1
a7 1
# Revision:      $FreeBSD: ports/www/resin2/files/resinctl,v 1.2 2005/04/15 00:30:48 hq Exp $
d157 1
a157 1
    COMMAND = "%%JAVA%%"
a167 1
    os.environ['JAVA_HOME'] = "%%JAVA_HOME%%"
d169 1
@


1.2
log
@- Unbreak: variable evaluation (WRKSRC) could not postponed due to some .for
  loops. The loops are now either unrolled or implemented as shell loops. [1]
- ECHO_CMD -> ECHO_MSG when displaying information to the user
- Improve resinctl [2]

PR:		79707
Submitted by:	Boris Kovalenko <boris@@tagnet.ru> [1], maintainer [2]
Approved by:	maintainer
@
text
@d7 1
a7 1
# Revision:      $FreeBSD: ports/www/resin2/files/resinctl,v 1.1 2005/02/24 22:27:53 hq Exp $
d160 1
a160 2
    if os.environ.has_key('JAVA_OPTS'):
        ARGS += os.environ['JAVA_OPTS'].split(" ")
d171 1
a171 1
    if len(sys.argv) != 2:
d175 1
a175 1
    if sys.argv[1] == "start":
d178 1
a178 1
    elif sys.argv[1] == "stop":
d181 1
a181 1
    elif sys.argv[1] == "restart":
@


1.1
log
@- Update to 2.1.16 [1]
- Replace perl wrapper with a new python control script and an RCng startup
  script [1]
- Use standard tab length [1]
- Update to bsd.java.mk 2.0
- Add $FreeBSD$ tags

PR:		77988 [1]
Submitted by:	maintainer [1]
@
text
@d7 1
a7 1
# Revision:      $FreeBSD$
d108 1
a108 1
    (unused_pid, status) = os.waitpid(pid, os.WNOHANG)
d111 1
a111 1
    if unused_pid != 0 and os.WIFEXITED(status):
a155 1
    CONTROL_PROGRAM = "%%APP_NAME%%ctl"
@

