在ubuntu9.10/sles11上安装resin并配置开机启动中遭遇的诸多有关问题

在ubuntu9.10/sles11下安装resin并配置开机启动中遭遇的诸多问题

有两年多没有使用resin了,最近打算在机器上安装一个web container跑点java web app,同时也可能需要支持php,原本打算用apache + tomcat,apache可以加载php模块来提供php支持,tomcat作为java web container。但突然想到resin,似乎是可以直接支持php的,而且resin的速度也是稍微快于tomcat,于是跑到resin的官网看了一下,恩,新出了4.0版本(惭愧,两年前用的是3.0或者3.1)。

    决定用resin试试,老朋友了。但是在安装过程中,发现了一系列问题,尤其是设置开机自动启动,记录下来提供大家参考。

    家里有台服务器,原来安装的是ubuntu 9.10的desktop版本,主要是考虑到ubuntu在作为桌面时非常不错,顺便做服务器。

(1) 下载
    从resin的官网 下载到最新的linux版本4.0.5:

http://www.caucho.com/download/resin-4.0.5.tar.gz。

(2) 安装
    先解压缩,然后重名为resin

    gunzip resin - 4.0 . 5 .tar.gz
    tar xvf resin
- 4.0 . 5 .tar
    move resin
- 4.0 . 5  resin
    cd resin
    .
/ configuration --prefix=/work/soft/resin



问题1. ubuntu下JAVA_HOME出错

在这里遇到一个特别奇怪的问题,我明明设置了JAVA_HOME而且肯定路径是有效的,但是resin就是报错:

checking  for  JAVA_HOME...
configure: error: Can
' t find valid JAVA_HOME


检查env:

env  |  grep JAVA
JAVA_HOME
=/ usr / local / java / jdk1. 6


再看目标路径/ usr / local / java / jdk1. 6 ,没有问题。有点郁闷,莫名其妙,于是找到resin官网的说明文档resin installation quick start ,发现一句话,"On Unix, set the JAVA_HOME variable or link /usr/java to the java home."。 好吧,试试/usr/java这个办法,

ln  - / usr / local / java / jdk1. 6   / usr / java


再执行configure就不再出错了(补充,这个问题只在ubuntu 9.10出现,后来在suse sles11上没有出现,sles只要JAVA_HOME正确就可以了),接着

make
make install


安装完成,但是报错,应该是没有/etc/init.d/resin的写权限,这样就无法实现开机自动启动resin。

****************************************************************
WARNING: Unable to install 
/ etc / init.d / resin
         Destination is not writable. Usually, only root has
         permissions to install 
this  file.

         This file is not required, but is used to start Resin
         at boot time.
****************************************************************


启动resin,然后用浏览器访问http://192.168.0.40:8080/,成功。

cd bin
.
/ resin.sh start



(3) 快捷设置

1. 为了方便使用resin,编辑.profile文件,加入一些别名:

#resin
RESIN_HOME=/work/soft/resin
alias cd_resin="cd $RESIN_HOME"
alias resin_start="$RESIN_HOME/bin/resin.sh start"
alias resin_stop="$RESIN_HOME/bin/resin.sh stop"
alias resin_restart="$RESIN_HOME/bin/resin.sh restart"

执行 source .profile导入。

(4) 开机自动运行

问题2: ubuntu 下开机自动运行设置无效

以前install  / etc / init.d / resin失败, 只好自己动手了,将resin/init.d/resin(make 后生成) 这个文件复制过去:

sudo cp init.d / resin  / etc / init.d / resin
sudo chmod 
+ / etc / init.d / resin
sudo update
- rc.d resin defaults


重启之后,发现resin没有启动起来。反复检查init.d/rc.d的设置,google了n多文档,实验了很多次,始终都是无效!!极其郁闷。
后来看到一些说法,ubuntu在很多设置上和一般常见的linux发行版本不大相同,比如没有chkconfig,需要使用update - rc.d等,考虑一般也不怎么用linux桌面,ubuntu在server上用的比较少。手头又正好有个suse sles 11的安装盘,于是一时冲动,决定换个linux版本,以后用suse好了。(从后面的情况,问题不在ubuntu上,算是我冤枉ubuntu了)。

suse安装的过程不提,后面会有单独的文章做安装记录。安装好之后,直奔主题,安装jdk和resin。一路顺风,直到再次执行到安装resin的开启启动

问题3. suse slse 11
下启动自动运行设置无效

sudo cp init.d / resin  / etc / init.d / resin
sudo chmod 
+ / etc / init.d / resin
sudo chkconfig resin on

   上面算是标准的resin开机启动设置了,结果重启后发现无效。很郁闷,linux版本都换了,还是同样结果。

    试着直接使用/ etc / init.d / resin来启动resin,模拟开机时的系统调用:

. / resin start
.
/ resin: line  86 : log_daemon_msg: command not found
.
/ resin: line  96 : log_end_msg: command not found


    意外发现上面的错误提示,打开/ etc / init.d / resin ,以下是启动的脚本片段:

log_daemon_msg  " Starting resin "
if  test  - / lib / lsb / init - functions; then
  . 
/ lib / lsb / init - functions
else
  log_daemon_msg () {
      
if  [  - " $1 "  ]; then
          
return   1
      fi

          
return   1
      fi
      
if  [  - " $2 "  ]; then
          echo 
- " $1: "
          
return
      fi
      echo 
- " $1: $2 "
  }
  log_end_msg () {
      [ 
- " $1 "  ]  &&   return   1
      
if  [ $ 1   - eq  0  ]; then
        echo 
"  . "
      
else
        echo 
"  failed! "
      fi
    
return  $ 1
  }
fi


    从这个if语句看,如果/ lib / lsb / init - functions存在就载入 / lib / lsb / init - functions的内容,否则就自己定义相关的两个函数。vi打开 / lib / lsb / init - functions,发现问题:里面根本没有 log_daemon_msg() / log_end_msg()两个方法!
    解决的方法简单,删除掉这个if,直接使用自定义的函数好了。
    之后重新执行,resin正常启动,resin的初始化页面可以访问。


    很高兴的重启suse,结果还是发现有问题,resin没有起来!继续,ps看进程发现resin 的watchdog进程启动了,但是resin的进程没有起来。找到resin的log,发现在watchdog-manager.log中有大量的异常:

java.lang.IllegalArgumentException: www - data is an unknown user
                                at com.caucho.bootjni.JniProcess.exec(Native Method)
                                at com.caucho.bootjni.JniProcess.
< init > (JniProcess.java: 91 )
                                at com.caucho.bootjni.JniProcess.create(JniProcess.java:
124 )
                                at com.caucho.bootjni.JniBoot.exec(JniBoot.java:
69 )
                                at com.caucho.boot.WatchdogChildProcess.createProcess(WatchdogChildProcess.java:
381 )
                                at com.caucho.boot.WatchdogChildProcess.run(WatchdogChildProcess.java:
126 )
                                at com.caucho.boot.WatchdogChildTask.run(WatchdogChildTask.java:
174 )
                                at com.caucho.util.ThreadPool$PoolThread.runTasks(ThreadPool.java:
901 )
                                at com.caucho.util.ThreadPool$PoolThread.run(ThreadPool.java:
866 )



怀疑是这个造成的,watch dog 启动resin时遭遇异常,因此resin没有启动,而watch dog的进程在,和ps的结果符合。实验了一下,删除所有log文件。使用/etc/init.d/resin start命令直接启动resin,成功,查看日志文件没有异常。

再次清空日志文件,重启resin,启动后ps看进程,并查看watchdog-manager.log,上面的现象重现。问题就应该在这里了,"www - data is an unknown user ",用命令看了一下的确系统中不存在所谓的www-data用户,因此问题聚焦到,www-data是哪里冒出来的?很明显直接启动resin时是不会遇到这个问题的。

google "www-data resin"有所发现:在caucho的wiki发现对此的描述:

http://wiki.caucho.com/Migrating_from_Resin_3.0_to_Resin_4.0

Unix allows only root to bind to ports below  1024 . If you use Resin as your webserver
(recommended) and bind to port 
80 , you ' ll need to start Resin as root. In Resin 4.0, the
Resin process can drop privileges as soon as it ' s bound to all its ports. You can configure

the user that Resin uses in the 
< server >  or  < server - default >   sections:

 
< server - default >
     
< resin: if  test = " ${resin.userName == 'root'} " >
       
< user - name > www - data </ user - name >
       
< group - name > www - data </ group - name >
     
</ resin: if >



问题应该在这里了,如果当前用户是root(开机启动时当然只能是root),resin就会使用这里设置的user/group,resin配置文件中默认是www-data/www-data,而这www-data/www-data肯定是不会默认存在的,因此造成上述resin无法启动的问题。

    打开resin/conf/resin.xml,找到以下内容:

      <!--
         - If starting Resin as root on Unix, specify the user name
         - and group name for the web server user.
        
-->
      
< resin:if  test ="${resin.userName == 'root'}" >
        
< user-name > www-data </ user-name >
        
< group-name > www-data </ group-name >
      
</ resin:if >


    修改user-name/gourp-name为有效user/group,保存。重启suse,这次resin终于正常的启动了,不容易啊。这个www-data的问题估计是resin4.0版本之后带入的,因为以前用3.0版本没有发现类似问题。奇怪的是,resin的安装文档中绝口不提这个东东,呵呵,浪费我不少时间。