今天是: 收藏本站 设为主页
网站首页 >  技术专栏  >  linux  > 

linux下自动启动openoffice 转换程序soffice.bin

日期:2013-04-15  点击率:4194


hylafax会用到ms office转换程序,需要启动一个服务监听程序,监听8100端口。可以通过设置让系统自动启动该服务。

1、创建一个执行脚本runoffice,内容如下
#vi /usr/sbin/runoffice
/usr/bin/nohup /usr/lib64/libreoffice/program/soffice.bin "--accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" --norestore --nofirststartwizard --nologo --headless &
#chmod 775 /usr/sbin/runoffice
2、创建启动脚本
#cat /etc/rc.d/rc.local

$ cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
xhost +
export DISPLAY=:0.0
/usr/sbin/runoffice >/var/log/rc.local.log

touch /var/lock/subsys/local

上述脚本会在所有服务启动完之后执行。

注意
xhost +
export DISPLAY=:0.0
要不然是不会启动成功的,会显示如下错误信息
/program/soffice.bin X11 error: Can't open display:
Set DISPLAY environment variable, use -display option
or check permissions of your X-Server
(See "man X" resp. "man xhost" for details)
加上那两行就会顺利启动了。

3、在 Centos上作为服务启动
经过一段时间的试用,发现2中的启动脚本有时能够成功,有时不能成功。
经过google搜索,有个服务启动脚本,经过修改以后,可以适用。

3.1 需要安装Xvfb,是一个虚拟XServer
In the X Window System, Xvfb or X virtual framebuffer is an X11 server that performs all graphical operations in memory, not showing any screen output. From the point of view of the client, it acts exactly like any other server, serving requests and sending events and errors as appropriate. However, no output is shown. This virtual server does not require the computer it is running on to even have a screen or any input device. Only a network layer is necessary.

它的图形只存在内存中,而不显示。

#yum seach Xvfb

#yum xorg-x11-server-Xvfb.x86_64

3.2 在/etc/init.d/创建服务启动脚本

下面是修改后适合Centos 6.3的 脚本内容

#cat /etc/init.d/soffice

#!/bin/bash

# Boot open office so that Alfresco can do transforms.
# chkconfig: 2345 55 25
# description: OpenOffice Headless
#
# processname: soffice

# source function library
. /etc/rc.d/init.d/functions

RETVAL=0

VDISPLAY='99'
SOFFICE_PATH='/usr/lib64/libreoffice/program/'
SOFFICE_ARGS1="-nofirststartwizard -nologo -headless -display :$VDISPLAY "
SOFFICE_ARGS2='-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager'
SOFFICE_PIDFILE=/var/run/soffice.bin.pid

XVFB=/usr/bin/Xvfb
XVFB_ARGS=":$VDISPLAY -screen 0 800x600x8 -fbdir /var/run"
XVFB_PIDFILE=/var/run/xvfb.pid
start_soffice() {
echo -n $"Starting OpenOffice"
$SOFFICE_PATH/soffice.bin $SOFFICE_ARGS1 $SOFFICE_ARGS2 >/dev/null 2>&1 &
[ $? -eq 0 ] && echo_success || echo_failure
pidof soffice.bin > $SOFFICE_PIDFILE
echo
}
start_xvfb() {
echo -n $"Starting Xvfb"
$XVFB $XVFB_ARGS >/dev/null 2>&1 &
[ $? -eq 0 ] && success || failure
pidofproc Xvfb > $XVFB_PIDFILE
echo
}
start() {
start_xvfb
sleep 3
start_soffice
}
stop() {
echo -n $"Stopping OpenOffice"
killproc soffice.bin
echo
echo -n $"Stopping Xvfb"
killproc Xvfb
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
esac

#chkconfig soffice on



下一篇:简化开发任务的20个JavaScript类库   上一篇:分享几个国外模板网站(网页素材的下载)