You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-commits@incubator.apache.org by ng...@apache.org on 2007/01/24 09:36:32 UTC
svn commit: r499329 - in /incubator/ftpserver/trunk:
core/src/java/org/apache/ftpserver/commandline/Daemon.java
distribution/bin/ftpd.exe distribution/bin/ftpdw.exe
distribution/bin/service.bat
distribution/src/main/assemblies/bin-with-dependencies.xml
Author: ngn
Date: Wed Jan 24 01:36:31 2007
New Revision: 499329
URL: http://svn.apache.org/viewvc?view=rev&rev=499329
Log:
Adding support for installing FtpServer as a Windows service (FTPSERVER-24)
Added:
incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/commandline/Daemon.java (with props)
incubator/ftpserver/trunk/distribution/bin/ftpd.exe (with props)
incubator/ftpserver/trunk/distribution/bin/ftpdw.exe (with props)
incubator/ftpserver/trunk/distribution/bin/service.bat (with props)
Modified:
incubator/ftpserver/trunk/distribution/src/main/assemblies/bin-with-dependencies.xml
Added: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/commandline/Daemon.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/commandline/Daemon.java?view=auto&rev=499329
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/commandline/Daemon.java (added)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/commandline/Daemon.java Wed Jan 24 01:36:31 2007
@@ -0,0 +1,103 @@
+package org.apache.ftpserver.commandline;
+
+import java.io.FileInputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ftpserver.ConfigurableFtpServerContext;
+import org.apache.ftpserver.FtpServer;
+import org.apache.ftpserver.config.PropertiesConfiguration;
+import org.apache.ftpserver.config.XmlConfigurationHandler;
+import org.apache.ftpserver.ftplet.Configuration;
+import org.apache.ftpserver.ftplet.EmptyConfiguration;
+import org.apache.ftpserver.ftplet.FtpException;
+import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.util.IoUtils;
+
+public class Daemon {
+
+ private static Log log = LogFactory.getLog(Daemon.class);
+
+ private static FtpServer server;
+ private static Object lock = new Object();
+
+ public static void main(String[] args) throws Exception {
+ try{
+ if(server == null) {
+ // get configuration
+ Configuration config = getConfiguration(args);
+ if(config == null) {
+ log.error("No configuration provided");
+ throw new FtpException("No configuration provided");
+ }
+
+ // create root configuration object
+ FtpServerContext serverContext = new ConfigurableFtpServerContext(config);
+
+ // start the server
+ server = new FtpServer(serverContext);
+ }
+
+ String command = "start";
+
+ if(args != null && args.length > 0) {
+ command = args[0];
+ }
+
+
+ if(command.equals("start")) {
+ log.info("Starting FTP server daemon");
+ server.start();
+
+ synchronized (lock) {
+ lock.wait();
+ }
+ } else if(command.equals("stop")) {
+ synchronized (lock) {
+ lock.notify();
+ }
+ log.info("Stopping FTP server daemon");
+ server.stop();
+ }
+ } catch(Throwable t) {
+ log.error("Daemon error", t);
+ }
+ }
+
+ /**
+ * Get the configuration object.
+ */
+ private static Configuration getConfiguration(String[] args) throws Exception {
+
+ Configuration config = null;
+ FileInputStream in = null;
+ try {
+ if(args == null || args.length < 2) {
+ log.info("Using default configuration....");
+ config = EmptyConfiguration.INSTANCE;
+ }
+ else if( (args.length == 2) && args[1].equals("-default") ) {
+ log.info("Using default configuration....");
+ config = EmptyConfiguration.INSTANCE;
+ }
+ else if( (args.length == 3) && args[1].equals("-xml") ) {
+ log.info("Using xml configuration file " + args[2] + "...");
+ in = new FileInputStream(args[2]);
+ XmlConfigurationHandler xmlHandler = new XmlConfigurationHandler(in);
+ config = xmlHandler.parse();
+ }
+ else if( (args.length == 3) && args[1].equals("-prop") ) {
+ log.info("Using properties configuration file " + args[2] + "...");
+ in = new FileInputStream(args[2]);
+ config = new PropertiesConfiguration(in);
+ } else {
+ throw new FtpException("Invalid configuration option");
+ }
+ }
+ finally {
+ IoUtils.close(in);
+ }
+
+ return config;
+ }
+}
Propchange: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/commandline/Daemon.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ftpserver/trunk/distribution/bin/ftpd.exe
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/distribution/bin/ftpd.exe?view=auto&rev=499329
==============================================================================
Binary file - no diff available.
Propchange: incubator/ftpserver/trunk/distribution/bin/ftpd.exe
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/ftpserver/trunk/distribution/bin/ftpdw.exe
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/distribution/bin/ftpdw.exe?view=auto&rev=499329
==============================================================================
Binary file - no diff available.
Propchange: incubator/ftpserver/trunk/distribution/bin/ftpdw.exe
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/ftpserver/trunk/distribution/bin/service.bat
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/distribution/bin/service.bat?view=auto&rev=499329
==============================================================================
--- incubator/ftpserver/trunk/distribution/bin/service.bat (added)
+++ incubator/ftpserver/trunk/distribution/bin/service.bat Wed Jan 24 01:36:31 2007
@@ -0,0 +1,116 @@
+@echo off
+if "%OS%" == "Windows_NT" setlocal
+rem ---------------------------------------------------------------------------
+rem NT Service Install/Uninstall script
+rem
+rem Options
+rem install Install the service using Tomcat5 as service name.
+rem Service is installed using default settings.
+rem remove Remove the service from the System.
+rem
+rem name (optional) If the second argument is present it is considered
+rem to be new service name
+rem
+rem $Id: service.bat 467182 2006-10-23 23:47:06Z markt $
+rem ---------------------------------------------------------------------------
+
+rem Guess CATALINA_HOME if not defined
+set CURRENT_DIR=%cd%
+if not "%FTPD_HOME%" == "" goto gotHome
+set FTPD_HOME=%cd%
+if exist "%FTPD_HOME%\bin\ftpd.exe" goto okHome
+rem CD to the upper dir
+cd ..
+set FTPD_HOME=%cd%
+:gotHome
+if exist "%FTPD_HOME%\bin\ftpd.exe" goto okHome
+echo The ftpd.exe was not found...
+echo The FTPD_HOME environment variable is not defined correctly.
+echo This environment variable is needed to run this program
+goto end
+rem Make sure prerequisite environment variables are set
+if not "%JAVA_HOME%" == "" goto okHome
+echo The JAVA_HOME environment variable is not defined
+echo This environment variable is needed to run this program
+goto end
+:okHome
+
+set EXECUTABLE=%FTPD_HOME%\bin\ftpd.exe
+
+rem Set default Service name
+set SERVICE_NAME=ftpd
+set PR_DISPLAYNAME=Apache FtpServer
+
+if "%1" == "" goto displayUsage
+if "%2" == "" goto setServiceName
+set SERVICE_NAME=%2
+set PR_DISPLAYNAME=Apache Tomcat %2
+:setServiceName
+if %1 == install goto doInstall
+if %1 == remove goto doRemove
+if %1 == uninstall goto doRemove
+echo Unknown parameter "%1"
+:displayUsage
+echo.
+echo Usage: service.bat install/remove [service_name]
+goto end
+
+:doRemove
+rem Remove the service
+"%EXECUTABLE%" //DS//%SERVICE_NAME%
+echo The service '%SERVICE_NAME%' has been removed
+goto end
+
+:doInstall
+rem Install the service
+echo Installing the service '%SERVICE_NAME%' ...
+echo Using FTPD_HOME: %FTPD_HOME%
+echo Using JAVA_HOME: %JAVA_HOME%
+
+rem ----- Create CLASSPATH --------------------------------------------
+set FTPD_CLASSPATH=%FTPD_HOME%\common\classes
+cd /d "%FTPD_HOME%\common\lib"
+for %%i in ("*.jar") do call "%FTPD_HOME%\bin\appendcp.bat" "%FTPD_HOME%\common\lib\%%i"
+cd /d %FTPD_HOME%
+
+rem Use the environment variables as an example
+rem Each command line option is prefixed with PR_
+
+set FTPD_LOGPATH=%FTPD_HOME%\res\log
+
+set PR_DESCRIPTION=Apache FtpServer (http://incubator.apache.org/ftpserver/)
+set PR_INSTALL=%EXECUTABLE%
+set PR_LOGPATH=%FTPD_LOGPATH%
+set PR_CLASSPATH=%FTPD_CLASSPATH%
+rem Set the server jvm from JAVA_HOME
+set PR_JVM=%JAVA_HOME%\jre\bin\server\jvm.dll
+if exist "%PR_JVM%" goto foundJvm
+rem Set the client jvm from JAVA_HOME
+set PR_JVM=%JAVA_HOME%\jre\bin\client\jvm.dll
+if exist "%PR_JVM%" goto foundJvm
+set PR_JVM=auto
+:foundJvm
+echo Using JVM: %PR_JVM%
+"%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.ftpserver.commandline.Daemon --StartParams start --StartPath "%FTPD_HOME%" --StopClass org.apache.ftpserver.commandline.Daemon --StopParams stop
+if not errorlevel 1 goto installed
+echo Failed installing '%SERVICE_NAME%' service
+goto end
+:installed
+rem Clear the environment variables. They are not needed any more.
+set PR_DISPLAYNAME=
+set PR_DESCRIPTION=
+set PR_INSTALL=
+set PR_LOGPATH=
+set PR_CLASSPATH=
+set PR_JVM=
+rem Set extra parameters
+"%EXECUTABLE%" //US//%SERVICE_NAME% --StartMode jvm --StopMode jvm --StdOutput "%FTPD_LOGPATH%\out.log" --StdError "%FTPD_LOGPATH%\error.log"
+rem More extra parameters
+set PR_LOGPATH=%FTPD_HOME%\logs
+set PR_STDOUTPUT=auto
+set PR_STDERROR=auto
+REM "%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp" --JvmMs 128 --JvmMx 256
+echo The service '%SERVICE_NAME%' has been installed.
+
+:end
+cd %CURRENT_DIR%
Propchange: incubator/ftpserver/trunk/distribution/bin/service.bat
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ftpserver/trunk/distribution/src/main/assemblies/bin-with-dependencies.xml
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/distribution/src/main/assemblies/bin-with-dependencies.xml?view=diff&rev=499329&r1=499328&r2=499329
==============================================================================
--- incubator/ftpserver/trunk/distribution/src/main/assemblies/bin-with-dependencies.xml (original)
+++ incubator/ftpserver/trunk/distribution/src/main/assemblies/bin-with-dependencies.xml Wed Jan 24 01:36:31 2007
@@ -28,6 +28,7 @@
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.bat</include>
+ <include>*.exe</include>
</includes>
</fileSet>
<fileSet>