无法启动tomcat作为用户

时间:2017-06-28 13:11:17

标签: tomcat7 centos7

我正在使用Centos7和tomcat 7.我需要使用systemd服务脚本将tomcat作为'tomcat'用户运行。我使用了here

中的脚本

它可以工作,但它会抛出异常

56:40.051[%!-5.5p]: ##VelocityEngineInitializationException## --> (ConfigurationAndResourceIntializationHandler.java:78)
com.sz.api.common.exceps.VelocityEngineInitializationException: ##Exception##
        at com.sz.api.services.velocityengine.VelocityEngineHandler.initializeVelocityEngine(VelocityEngineHandler.java:64)
        at com.sz.api.engine.alert.bootup.ConfigurationAndResourceIntializationHandler.initializeVelocityEngine(ConfigurationAndResourceIntializationHandler.java:230)
        at com.sz.api.engine.alert.bootup.ConfigurationAndResourceIntializationHandler.configureHandler(ConfigurationAndResourceIntializationHandler.java:61)
        at com.sz.api.engine.alert.driver.AlertEngineDriver.startSystem(AlertEngineDriver.java:40)
        at com.sz.api.ws.bootstrap.StartUpService.initializeAlertEngine(StartUpService.java:309)
        at com.sz.api.ws.bootstrap.StartUpService.init(StartUpService.java:70)
        at javax.servlet.GenericServlet.init(GenericServlet.java:160)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1267)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1186)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1081)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
        at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
        at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
        at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
        at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
        at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:107)
        at com.sz.api.services.velocityengine.VelocityEngineHandler.initializeVelocityEngine(VelocityEngineHandler.java:53)
        ... 22 more
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute :
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.apache.velocity.util.ExceptionUtils.createWithCause(ExceptionUtils.java:67)
        at org.apache.velocity.util.ExceptionUtils.createRuntimeException(ExceptionUtils.java:45)
        at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:133)
        at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85)
        at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
        ... 27 more
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:142)
        at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
        at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:207)
        at org.apache.log4j.FileAppender.<init>(FileAppender.java:110)
        at org.apache.log4j.RollingFileAppender.<init>(RollingFileAppender.java:79)
        at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118)
        ... 29 more

当然,我检查了velocity.log权限,一切都很好。只有当我将tomcat作为'tomcat'用户运行时才会出现此错误。请指教!

1 个答案:

答案 0 :(得分:0)

试试这个:

  1. 找到velocity.log的位置:

    def tail(theFile):
        theFile.seek(0, 2) 
        while not theFile.closed:
            line = theFile.readline()
            ...
            yield line
    
  2. 检查velocity.log的权限:

    $ cd /
    $ find -name "velocity.log"
    
  3. 如果不合适,请更改所有者:

    $ ls -la velocity.log