# 開機啟動 Seafile
### Ubuntu 下
Ubuntu下,我們使用了這個[/etc/init.d/](https://help.ubuntu.com/community/UbuntuBootupHowto)這個腳本來設置Seafile/Seahub 開機啟動.
### 創建**/etc/init.d/seafile-server**腳本
~~~
sudo vim /etc/init.d/seafile-server
~~~
腳本內容為: (同時需要修改相應的`user`和`script\_path`字段的值)
~~~
#!/bin/sh
# 請將 user 改為你的Linux用戶名
user=haiwen
# 請將 script_dir 改為你的 Seafile 文件安裝路徑
seafile_dir=/data/haiwen
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log
# 若使用 fastcgi, 請將其設置為true
fastcgi=false
# fastcgi 端口, 默認為 8000.
fastcgi_port=8000
case "$1" in
start)
sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
fi
;;
restart)
sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
fi
;;
stop)
sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}
sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
;;
*)
echo "Usage: /etc/init.d/seafile {start|stop|restart}"
exit 1
;;
esac
~~~
**注意**: 如果你想在 fastcgi 下運行 Seahub,請設置`fastcgi`變量為`true`
### 為日志文件創建目錄
~~~
mkdir /path/to/seafile/dir/logs
~~~
### 創建**/etc/init/seafile-server.conf**文件
#### 非使用 MySQL
~~~
start on (runlevel [2345])
stop on (runlevel [016])
pre-start script
/etc/init.d/seafile-server start
end script
post-stop script
/etc/init.d/seafile-server stop
end script
~~~
#### 使用 MySQL
~~~
start on (started mysql
and runlevel [2345])
stop on (runlevel [016])
pre-start script
/etc/init.d/seafile-server start
end script
post-stop script
/etc/init.d/seafile-server stop
end script
~~~
### 設置 seafile-sever 腳本為可執行文件
~~~
sudo chmod +x /etc/init.d/seafile-server
~~~
### 完成
在升級 Seafile 服務器后請記得更新`script\_path`的值.
### 其他 Debian 系的 Linux 下
### 創建腳本**/etc/init.d/seafile-server**
~~~
sudo vim /etc/init.d/seafile-server
~~~
腳本內容為: (同時需要修改相應的`user`和`script\_path`字段的值)
~~~
#!/bin/sh
### BEGIN INIT INFO
# Provides: seafile-server
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts Seafile Server
# Description: starts Seafile Server
### END INIT INFO
# 請將 user 改為你的Linux用戶名
user=haiwen
# 請將 script_path 改為你的 Seafile 文件安裝路徑
seafile_dir=/data/haiwen
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log
# 若使用 fastcgi, 請將其設置為true
fastcgi=false
# fastcgi 端口, 默認為 8000.
fastcgi_port=8000
case "$1" in
start)
sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
fi
;;
restart)
sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
fi
;;
stop)
sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}
sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
;;
*)
echo "Usage: /etc/init.d/seafile {start|stop|restart}"
exit 1
;;
esac
~~~
**注意**: 如果你想在 fastcgi 下運行 Seahub,請設置`fastcgi`變量為`true`
### 為日志文件創建目錄
~~~
mkdir /path/to/seafile/dir/logs
~~~
### 設置 seafile-sever 腳本為可執行文件
~~~
sudo chmod +x /etc/init.d/seafile-server
~~~
### 在 rc.d 中新增 seafile-server
~~~
sudo update-rc.d seafile-server defaults
~~~
### 完成
在升級 Seafile 服務器后請記得更新`script\_path`的值.
### RHEL/CentOS 下
RHEL/CentOS 下,[/etc/rc.local](http://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-run-boot.html)腳本會隨系統開機自動執行,所以我們在這個腳本中設置啟動Seafile/Seahub.
- 定位 python(python 2.6 or 2.7)
~~~
which python2.6 # or "which python2.7"
~~~
- 在 /etc/rc.local 腳本中, 將 python2.6(2.7)路徑加入到**PATH**字段中,并增加 Seafile/Seahub 啟動命令
~~~
`
# 假設 python 2.6(2.7) 可執行文件在 /usr/local/bin 目錄下
PATH=$PATH:/usr/local/bin/
# 請將 user 改為你的Linux用戶名
user=haiwen
# 請將 script_path 改為你的 Seafile 文件安裝路徑
seafile_dir=/data/haiwen
script_path=${seafile_dir}/seafile-server-latest
sudo -u ${user} ${script_path}/seafile.sh start > /tmp/seafile.init.log 2>&1
sudo -u ${user} ${script_path}/seahub.sh start > /tmp/seahub.init.log 2>&1
~~~
**注意**: 如果你想在fastcgi下啟動Seahub,只需將上文中最后一行**"seahub.sh start"**改為**"seahub.shstart-fastcgi"**
- 完成. 在升級 Seafile 服務器后請記得更新 `script\_pat` 的值.
### 只使用 RHEL/CentOS 為服務程序(service)下
RHEL/CentOS 下 , 我們通過 /etc/init.d/ 腳本將 Seafile/Seahub作為服務程序隨開機啟動.
### 創建**/etc/sysconfig/seafile**文件
~~~
# 請將 user 改為你的Linux用戶名
user=haiwen
# 請將 script_path 改為你的 Seafile 文件安裝路徑
seafile_dir=/home/haiwen
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log
# 若使用 fastcgi, 請將其設置true
fastcgi=false
# fastcgi 端口, 默認為 8000.
fastcgi_port=8000
~~~
### 創建**/etc/init.d/seafile**文件
~~~
#!/bin/bash
#
# seafile
#
# chkconfig: - 68 32
# description: seafile
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
if [ -f /etc/sysconfig/seafile ];then
. /etc/sysconfig/seafile
else
echo "Config file /etc/sysconfig/seafile not found! Bye."
exit 200
fi
RETVAL=0
start() {
# Start daemons.
echo -n $"Starting seafile: "
ulimit -n 30000
su - ${user} -c"${script_path}/seafile.sh start >> ${seafile_init_log} 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/seafile
return $RETVAL
}
stop() {
echo -n $"Shutting down seafile: "
su - ${user} -c"${script_path}/seafile.sh stop >> ${seafile_init_log} 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seafile
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart}"
RETVAL=3
esac
exit $RETVAL
~~~
### 創建**/etc/init.d/seahub**腳本
~~~
#!/bin/bash
#
# seahub
#
# chkconfig: - 69 31
# description: seahub
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
if [ -f /etc/sysconfig/seafile ];then
. /etc/sysconfig/seafile
else
echo "Config file /etc/sysconfig/seafile not found! Bye."
exit 200
fi
RETVAL=0
start() {
# Start daemons.
echo -n $"Starting seahub: "
ulimit -n 30000
if [ $fastcgi = true ];
then
su - ${user} -c"${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log} 2>&1"
else
su - ${user} -c"${script_path}/seahub.sh start >> ${seahub_init_log} 2>&1"
fi
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/seahub
return $RETVAL
}
stop() {
echo -n $"Shutting down seafile: "
su - ${user} -c"${script_path}/seahub.sh stop >> ${seahub_init_log} 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seahub
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart}"
RETVAL=3
esac
exit $RETVAL
~~~
接下來啟動服務程序:
~~~
chmod 550 /etc/init.d/seafile
chmod 550 /etc/init.d/seahub
chkconfig --add seafile
chkconfig --add seahub
chkconfig seahub on
chkconfig seafile on
~~~
執行:
~~~
service seafile start
service seahub start
~~~
### 完成
- 介紹
- 概覽
- Seafile 組件
- 研發路線圖
- 常見問題解答
- 修改日志
- 我要參與
- Linux 下部署 Seafile 服務器
- 部署 Seafile 服務器(使用 SQLite)
- 部署 Seafile 服務器(使用 MySQL)
- Nginx 下配置 Seahub
- Nginx 下啟用 Https
- Apache 下配置 Seahub
- Apache 下啟用 Https
- Seafile LDAP 配置
- 開機啟動 Seafile
- 防火墻設置
- Logrotate 管理系統日志
- 使用 Memcached
- 使用 NAT
- 非根域名下部署 Seahub
- 從 SQLite 遷移至 MySQL
- 安裝常見問題
- 升級
- Windows 下部署 Seafile 服務器
- 下載安裝 Windows 版 Seafile 服務器
- 安裝 Seafile 為 Windows 服務
- 所用端口說明
- 升級
- 從 Windows 遷移到 Linux
- 垃圾回收
- 部署 Seafile 專業版服務器
- 下載安裝 Seafile 專業版服務器
- 從社區版遷移至專業版
- 升級
- Amazon S3 下安裝
- OpenStackSwift 下安裝
- Ceph 下安裝
- 配置選項
- 文件搜索說明
- 集群部署
- 集群中啟用搜索和后臺服務
- NFS 下集群安裝
- 常見問題解答
- 軟件許可協議
- 服務器個性化配置
- ccnet.conf
- seafile.conf
- seahub_settings.py
- 發送郵件提醒
- 個性化郵件提醒
- 用戶管理
- 存儲容量與文件上傳/下載大小限制
- 自定義 Web
- 管理員手冊
- 賬戶管理
- 日志
- 備份與恢復
- Seafile FSCK
- Seafile GC
- WebDAV 和 FUSE 擴展
- WebDAV 擴展
- FUSE 擴展
- 安全選項
- 安全特性
- 日志和審計
- 開發文檔
- 編譯 Seafile
- Linux
- Windows
- Max OS X
- Server
- 開發環境
- 編程規范
- Web API
- Python API
- 數據模型
- 服務器組件
- 同步算法