加载中...

开机启动 Seafile


开机启动 Seafile

Ubuntu 下

Ubuntu下,我们使用了这个/etc/init.d/这个脚本来设置Seafile/Seahub 开机启动.

创建/etc/init.d/seafile-server脚本

  1. sudo vim /etc/init.d/seafile-server

脚本内容为: (同时需要修改相应的userscript\_path字段的值)

  1. #!/bin/sh
  2. # 请将 user 改为你的Linux用户名
  3. user=haiwen
  4. # 请将 script_dir 改为你的 Seafile 文件安装路径
  5. seafile_dir=/data/haiwen
  6. script_path=${seafile_dir}/seafile-server-latest
  7. seafile_init_log=${seafile_dir}/logs/seafile.init.log
  8. seahub_init_log=${seafile_dir}/logs/seahub.init.log
  9. # 若使用 fastcgi, 请将其设置为true
  10. fastcgi=false
  11. # fastcgi 端口, 默认为 8000.
  12. fastcgi_port=8000
  13. case "$1" in
  14. start)
  15. sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}
  16. if [ $fastcgi = true ];
  17. then
  18. sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
  19. else
  20. sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
  21. fi
  22. ;;
  23. restart)
  24. sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}
  25. if [ $fastcgi = true ];
  26. then
  27. sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
  28. else
  29. sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
  30. fi
  31. ;;
  32. stop)
  33. sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}
  34. sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
  35. ;;
  36. *)
  37. echo "Usage: /etc/init.d/seafile {start|stop|restart}"
  38. exit 1
  39. ;;
  40. esac

注意: 如果你想在 fastcgi 下运行 Seahub,请设置fastcgi变量为true

为日志文件创建目录

  1. mkdir /path/to/seafile/dir/logs

创建/etc/init/seafile-server.conf文件

非使用 MySQL

  1. start on (runlevel [2345])
  2. stop on (runlevel [016])
  3. pre-start script
  4. /etc/init.d/seafile-server start
  5. end script
  6. post-stop script
  7. /etc/init.d/seafile-server stop
  8. end script

使用 MySQL

  1. start on (started mysql
  2. and runlevel [2345])
  3. stop on (runlevel [016])
  4. pre-start script
  5. /etc/init.d/seafile-server start
  6. end script
  7. post-stop script
  8. /etc/init.d/seafile-server stop
  9. end script

设置 seafile-sever 脚本为可执行文件

  1. sudo chmod +x /etc/init.d/seafile-server

完成

在升级 Seafile 服务器后请记得更新script\_path的值.

其他 Debian 系的 Linux 下

创建脚本/etc/init.d/seafile-server

  1. sudo vim /etc/init.d/seafile-server

脚本内容为: (同时需要修改相应的userscript\_path字段的值)

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: seafile-server
  4. # Required-Start: $local_fs $remote_fs $network
  5. # Required-Stop: $local_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Starts Seafile Server
  9. # Description: starts Seafile Server
  10. ### END INIT INFO
  11. # 请将 user 改为你的Linux用户名
  12. user=haiwen
  13. # 请将 script_path 改为你的 Seafile 文件安装路径
  14. seafile_dir=/data/haiwen
  15. script_path=${seafile_dir}/seafile-server-latest
  16. seafile_init_log=${seafile_dir}/logs/seafile.init.log
  17. seahub_init_log=${seafile_dir}/logs/seahub.init.log
  18. # 若使用 fastcgi, 请将其设置为true
  19. fastcgi=false
  20. # fastcgi 端口, 默认为 8000.
  21. fastcgi_port=8000
  22. case "$1" in
  23. start)
  24. sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}
  25. if [ $fastcgi = true ];
  26. then
  27. sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
  28. else
  29. sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
  30. fi
  31. ;;
  32. restart)
  33. sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}
  34. if [ $fastcgi = true ];
  35. then
  36. sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
  37. else
  38. sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
  39. fi
  40. ;;
  41. stop)
  42. sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}
  43. sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
  44. ;;
  45. *)
  46. echo "Usage: /etc/init.d/seafile {start|stop|restart}"
  47. exit 1
  48. ;;
  49. esac

注意: 如果你想在 fastcgi 下运行 Seahub,请设置fastcgi变量为true

为日志文件创建目录

  1. mkdir /path/to/seafile/dir/logs

设置 seafile-sever 脚本为可执行文件

  1. sudo chmod +x /etc/init.d/seafile-server

在 rc.d 中新增 seafile-server

  1. sudo update-rc.d seafile-server defaults

完成

在升级 Seafile 服务器后请记得更新script\_path的值.

RHEL/CentOS 下

RHEL/CentOS 下,/etc/rc.local脚本会随系统开机自动执行,所以我们在这个脚本中设置启动Seafile/Seahub.

  • 定位 python(python 2.6 or 2.7)
  1. which python2.6 # or "which python2.7"
  • 在 /etc/rc.local 脚本中, 将 python2.6(2.7)路径加入到PATH字段中,并增加 Seafile/Seahub 启动命令
  1. `
  2. # 假设 python 2.6(2.7) 可执行文件在 /usr/local/bin 目录下
  3. PATH=$PATH:/usr/local/bin/
  4. # 请将 user 改为你的Linux用户名
  5. user=haiwen
  6. # 请将 script_path 改为你的 Seafile 文件安装路径
  7. seafile_dir=/data/haiwen
  8. script_path=${seafile_dir}/seafile-server-latest
  9. sudo -u ${user} ${script_path}/seafile.sh start > /tmp/seafile.init.log 2>&1
  10. 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文件

  1. # 请将 user 改为你的Linux用户名
  2. user=haiwen
  3. # 请将 script_path 改为你的 Seafile 文件安装路径
  4. seafile_dir=/home/haiwen
  5. script_path=${seafile_dir}/seafile-server-latest
  6. seafile_init_log=${seafile_dir}/logs/seafile.init.log
  7. seahub_init_log=${seafile_dir}/logs/seahub.init.log
  8. # 若使用 fastcgi, 请将其设置true
  9. fastcgi=false
  10. # fastcgi 端口, 默认为 8000.
  11. fastcgi_port=8000

创建/etc/init.d/seafile文件

  1. #!/bin/bash
  2. #
  3. # seafile
  4. #
  5. # chkconfig: - 68 32
  6. # description: seafile
  7. # Source function library.
  8. . /etc/init.d/functions
  9. # Source networking configuration.
  10. . /etc/sysconfig/network
  11. if [ -f /etc/sysconfig/seafile ];then
  12. . /etc/sysconfig/seafile
  13. else
  14. echo "Config file /etc/sysconfig/seafile not found! Bye."
  15. exit 200
  16. fi
  17. RETVAL=0
  18. start() {
  19. # Start daemons.
  20. echo -n $"Starting seafile: "
  21. ulimit -n 30000
  22. su - ${user} -c"${script_path}/seafile.sh start >> ${seafile_init_log} 2>&1"
  23. RETVAL=$?
  24. echo
  25. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/seafile
  26. return $RETVAL
  27. }
  28. stop() {
  29. echo -n $"Shutting down seafile: "
  30. su - ${user} -c"${script_path}/seafile.sh stop >> ${seafile_init_log} 2>&1"
  31. RETVAL=$?
  32. echo
  33. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seafile
  34. return $RETVAL
  35. }
  36. # See how we were called.
  37. case "$1" in
  38. start)
  39. start
  40. ;;
  41. stop)
  42. stop
  43. ;;
  44. restart|reload)
  45. stop
  46. start
  47. RETVAL=$?
  48. ;;
  49. *)
  50. echo $"Usage: $0 {start|stop|restart}"
  51. RETVAL=3
  52. esac
  53. exit $RETVAL

创建/etc/init.d/seahub脚本

  1. #!/bin/bash
  2. #
  3. # seahub
  4. #
  5. # chkconfig: - 69 31
  6. # description: seahub
  7. # Source function library.
  8. . /etc/init.d/functions
  9. # Source networking configuration.
  10. . /etc/sysconfig/network
  11. if [ -f /etc/sysconfig/seafile ];then
  12. . /etc/sysconfig/seafile
  13. else
  14. echo "Config file /etc/sysconfig/seafile not found! Bye."
  15. exit 200
  16. fi
  17. RETVAL=0
  18. start() {
  19. # Start daemons.
  20. echo -n $"Starting seahub: "
  21. ulimit -n 30000
  22. if [ $fastcgi = true ];
  23. then
  24. su - ${user} -c"${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log} 2>&1"
  25. else
  26. su - ${user} -c"${script_path}/seahub.sh start >> ${seahub_init_log} 2>&1"
  27. fi
  28. RETVAL=$?
  29. echo
  30. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/seahub
  31. return $RETVAL
  32. }
  33. stop() {
  34. echo -n $"Shutting down seafile: "
  35. su - ${user} -c"${script_path}/seahub.sh stop >> ${seahub_init_log} 2>&1"
  36. RETVAL=$?
  37. echo
  38. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seahub
  39. return $RETVAL
  40. }
  41. # See how we were called.
  42. case "$1" in
  43. start)
  44. start
  45. ;;
  46. stop)
  47. stop
  48. ;;
  49. restart|reload)
  50. stop
  51. start
  52. RETVAL=$?
  53. ;;
  54. *)
  55. echo $"Usage: $0 {start|stop|restart}"
  56. RETVAL=3
  57. esac
  58. exit $RETVAL

接下来启动服务程序:

  1. chmod 550 /etc/init.d/seafile
  2. chmod 550 /etc/init.d/seahub
  3. chkconfig --add seafile
  4. chkconfig --add seahub
  5. chkconfig seahub on
  6. chkconfig seafile on

执行:

  1. service seafile start
  2. service seahub start

完成


还没有评论.