Ubuntu 14.04安装EtherPad并以服务启动
-
前前后后看了数篇文章,最后好歹终于是成功把EtherPad-lite搭起来了。先说明对Linux并不非常熟,教程有点儿大杂烩的意思,各位将就着看,反正最后肯定能跑起来。稍微整理了一下,过程供各位参考。
1. 添加一个用来跑EtherPad-lite的用户:sudo adduser --system --home=/opt/etherpad --group etherpad
2. 接下来需要安装Node.js,先把下边儿这堆东西装了sudo apt-get install g++ curl libssl-dev apache2-utils
3. 然后安装git-coresudo apt-get install git-core
4. 切到刚才新建立的etherpad用户sudo su - etherpad -s /bin/bash
5. 从源码安装node.jsgit clone git://github.com/joyent/node.git
``` cd node ```
目前node.js的最新版是v0.12.7,checkout这个版本
``` git checkout v0.12.7 ```
``` mkdir ~/local ```
``` ./configure –-prefix=$HOME/local/node ```
复制上边儿那行时,请务必注意prefix前边儿是不是两个横线全部复制了
``` make ```
如果提示没有make,就用apt-get安装一下make。这步时间巨长,在我的VPS上跑了大概15分钟。
``` make install ```
添加环境变量
``` echo ‘export PATH=$HOME/local/node/bin:$PATH’ >> ~/.profile ```
``` echo ‘export NODE_PATH=$HOME/local/node:$HOME/local/node/lib/node_modules’ >> ~/.profile ```
安装nmp
``` curl -L http://npmjs.org/install.sh | sh ```
6. 终于可以正式开始安装etherPad了,有点小激动
``` cd ~ ```
``` git clone git://github.com/ether/etherpad-lite.git ```
``` cd etherpad-lite ```
``` bin/run.sh ```
如果没问题,那么这时候你的9001端口已经可以访问了。这个实例是使用dirtyDB,然后没有配置管理员用户名密码的。
接下来,配置etherPad自动运行
Ctrl+C,把刚才的程序结束掉
7. 图省事,切回root
``` su root ```
打开 /etc/profile文件,最后添加下边儿两行
``` export PATH="$HOME/local/node/bin:$PATH" ```
``` export NODE_PATH="$HOME/local/node:$HOME/local/node/lib/node_modules" ```
8. 建日志相关的目录
``` mkdir /var/log/etherpad-lite ```
``` chown etherpad /var/log/etherpad-lite ```
``` chown -R etherpad /var/log/etherpad-lite ```
9. 建服务,这步非常非常的奇怪,文件必须以.conf结尾,否则就跑不起来
``` sudo vi /etc/init.d/etherpad-lite.conf ```
把下边儿的内容粘进去,调试这个文件调试得满眼都是眼泪,不细说了……
```
#!/bin/sh
### BEGIN INIT INFO
# Provides: etherpad-lite
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts etherpad lite
# Description: starts etherpad lite using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/etherpad/local/node/bin
LOGFILE=/var/log/etherpad-lite/etherpad-lite.log
EPLITE_DIR=/opt/etherpad/etherpad-lite
EPLITE_BIN=bin/safeRun.sh
USER=etherpad
GROUP=etherpad
DESC=EtherpadLite
NAME=etherpad-lite
set -e
. /lib/lsb/init-functions
start() {
echo "Starting $DESC... "
start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec $EPLITE_DIR/$EPLITE_BIN -- $LOGFILE || true
echo "done"
}
#We need this function to ensure the whole process tree will be killed
killtree() {
local _pid=$1
local _sig=${2-TERM}
for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
killtree ${_child} ${_sig}
done
kill -${_sig} ${_pid}
}
_stop() {
echo "Stopping $DESC... "
if test -f /var/run/$NAME.pid; then
while test -d /proc/$(cat /var/run/$NAME.pid); do
killtree $(cat /var/run/$NAME.pid) 15
sleep 0.5
done
rm /var/run/$NAME.pid
fi
echo "done"
}
status() {
status_of_proc -p /var/run/$NAME.pid "" "etherpad-lite" && exit 0 || exit $?
}
case "$1" in
start)
start
;;
stop)
_stop
;;
restart)
_stop
start
;;
status)
status
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0
```
保存退出
10. 设定文件可执行权限
``` chmod +x /etc/init.d/etherpad-lite.conf ```
11. 试一下
``` service etherpad-lite.conf start ```
如果没问题,那么打开/etc/rc.local文件,在exit 0 前面加上
``` service etherpad-lite.conf start ```
重启看看吧。