其他部署说明 - 开机启动 Seafile

优质
小牛编辑
129浏览
2023-12-01

对于运行 systemd 的系统

  • 例如 Debian 8 以及更新的版本,Ubuntu 15.04以及更新的版本。

创建 systemd 服务管理文件,将以下示例中 ${seafile_dir} 替换为您自己的 seaile 安装路径,并且将 user 指向真正运行seafile的用户。然后您需要重新加载 systemd 的守护进程:systemctl daemon-reload

创建 systemd 服务文件 /etc/systemd/system/seafile.service

  1. sudo vim /etc/systemd/system/seafile.service

文件内容如下:

  1. [Unit]
  2. Description=Seafile
  3. # add mysql.service or postgresql.service depending on your database to the line below
  4. After=network.target
  5. [Service]
  6. Type=oneshot
  7. ExecStart=${seafile_dir}/seafile-server-latest/seafile.sh start
  8. ExecStop=${seafile_dir}/seafile-server-latest/seafile.sh stop
  9. RemainAfterExit=yes
  10. User=seafile
  11. Group=seafile
  12. [Install]
  13. WantedBy=multi-user.target

创建 systemd 服务文件 /etc/systemd/system/seahub.service

  1. sudo vim /etc/systemd/system/seahub.service

文件内容如下(如果你想要运行fastcgi模式,请不要忘记修改它。)

  1. [Unit]
  2. Description=Seafile hub
  3. After=network.target seafile.service
  4. [Service]
  5. # change start to start-fastcgi if you want to run fastcgi
  6. ExecStart=${seafile_dir}/seafile-server-latest/seahub.sh start
  7. ExecStop=${seafile_dir}/seafile-server-latest/seahub.sh stop
  8. User=seafile
  9. Group=seafile
  10. Type=oneshot
  11. RemainAfterExit=yes
  12. [Install]
  13. WantedBy=multi-user.target

创建 systemd 服务文件 /etc/systemd/system/seafile-client.service (可选)

只有在你有了 seafile 控制台客户端并且希望开机运行此程序时你才需要创建此文件。

  1. sudo vim /etc/systemd/system/seafile-client.service

文件内容如下:

  1. [Unit]
  2. Description=Seafile client
  3. # Uncomment the next line you are running seafile client on the same computer as server
  4. # After=seafile.service
  5. # Or the next one in other case
  6. # After=network.target
  7. [Service]
  8. Type=oneshot
  9. ExecStart=/usr/bin/seaf-cli start
  10. ExecStop=/usr/bin/seaf-cli stop
  11. RemainAfterExit=yes
  12. User=seafile
  13. Group=seafile
  14. [Install]
  15. WantedBy=multi-user.target

设置服务开机自启动

  1. sudo systemctl enable seafile.service
  2. sudo systemctl enable seahub.service
  3. sudo systemctl enable seafile-client.service # 可选

对于使用 init 而非 systemd 的系统

Ubuntu 14.10 以及更旧的版本

在没有 systemd 的 Ubuntu 系统上,我们使用 /etc/init.d/ 脚本来设置 seafile/seahub 开机自启动。

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

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

脚本内容如下:(你需要根据实际情况修改 userseafile_dir 的值)

  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: seafile-server
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Seafile server
  9. # Description: Start Seafile server
  10. ### END INIT INFO
  11. # Change the value of "user" to your linux user name
  12. user=haiwen
  13. # Change the value of "seafile_dir" to your path of seafile installation
  14. # usually the home directory of $user
  15. seafile_dir=/data/haiwen
  16. script_path=${seafile_dir}/seafile-server-latest
  17. seafile_init_log=${seafile_dir}/logs/seafile.init.log
  18. seahub_init_log=${seafile_dir}/logs/seahub.init.log
  19. # Change the value of fastcgi to true if fastcgi is to be used
  20. fastcgi=false
  21. # Set the port of fastcgi, default is 8000. Change it if you need different.
  22. fastcgi_port=8000
  23. #
  24. # Write a polite log message with date and time
  25. #
  26. echo -e "n n About to perform $1 for seafile at `date -Iseconds` n " >> ${seafile_init_log}
  27. echo -e "n n About to perform $1 for seahub at `date -Iseconds` n " >> ${seahub_init_log}
  28. case "$1" in
  29. start)
  30. sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
  31. if [ $fastcgi = true ];
  32. then
  33. sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
  34. else
  35. sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
  36. fi
  37. ;;
  38. restart)
  39. sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
  40. if [ $fastcgi = true ];
  41. then
  42. sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
  43. else
  44. sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
  45. fi
  46. ;;
  47. stop)
  48. sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
  49. sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
  50. ;;
  51. *)
  52. echo "Usage: /etc/init.d/seafile-server {start|stop|restart}"
  53. exit 1
  54. ;;
  55. esac

注意: 如果你正在使用本地 mysql 服务,请将 # Required-Start: $remote_fs $syslog 替换为 # Required-Start: $remote_fs $syslog mysql.

确保 seafile-server 脚本可执行

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

添加 seafile-server 到 rc.d 中

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

注意: 如果你更新了你的 seafile 服务,不要忘记更新 script_path 的值。

其他基于 Debian 的发行版

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

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

脚本内容如下:(你需要根据实际情况修改 userseafile_dir 的值)

  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. # Change the value of "user" to linux user name who runs seafile
  12. user=haiwen
  13. # Change the value of "seafile_dir" to your path of seafile installation
  14. # usually the home directory of $user
  15. seafile_dir=/data/haiwen
  16. script_path=${seafile_dir}/seafile-server-latest
  17. seafile_init_log=${seafile_dir}/logs/seafile.init.log
  18. seahub_init_log=${seafile_dir}/logs/seahub.init.log
  19. # Change the value of fastcgi to true if fastcgi is to be used
  20. fastcgi=false
  21. # Set the port of fastcgi, default is 8000. Change it if you need different.
  22. fastcgi_port=8000
  23. #
  24. # Write a polite log message with date and time
  25. #
  26. echo -e "n n About to perform $1 for seafile at `date -Iseconds` n " >> ${seafile_init_log}
  27. echo -e "n n About to perform $1 for seahub at `date -Iseconds` n " >> ${seahub_init_log}
  28. case "$1" in
  29. start)
  30. sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
  31. if [ $fastcgi = true ];
  32. then
  33. sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
  34. else
  35. sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
  36. fi
  37. ;;
  38. restart)
  39. sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
  40. if [ $fastcgi = true ];
  41. then
  42. sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
  43. else
  44. sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
  45. fi
  46. ;;
  47. stop)
  48. sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
  49. sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
  50. ;;
  51. *)
  52. echo "Usage: /etc/init.d/seafile-server {start|stop|restart}"
  53. exit 1
  54. ;;
  55. esac

注意:

  1. 如果你想要以 fastcgi 模式运行 seahub ,只需要将 fastcgi 的值配置为 true

  2. 如果你是在 MySQL 下部署 Seafile,添加 “mysql” 到 Required-Start 那行:

  1. <!-- -->
  2. # Required-Start: $local_fs $remote_fs $network mysql

为日志添文件加目录

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

确保 seafile-server 脚本可执行

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

添加 seafile-server 到 rc.d

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

完成

如果你更新了你的 seafile 服务,不要忘记更新 script_path 的值。

RHEL/CentOS

在 RHEL/CentOS 上,脚本 /etc/re.local 会在系统启动时被执行,所以可以通过这个脚本来实现 seafile/seahub 开机自启。

  • 确定您的 python 版本 (python 2.6 或者 2.7)
  1. which python2.6 # 或者 "which python2.7"
  • 在 /etc/rc.local 中添加 python2.6(2.7) 的目录到 PATH,并且添加 seafile/seahub 的启动命令
  1. # Assume the python 2.6(2.7) executable is in "/usr/local/bin"
  2. PATH=$PATH:/usr/local/bin/
  3. # Change the value of "user" to your linux user name
  4. user=haiwen
  5. # Change the value of "seafile_dir" to your path of seafile installation
  6. # usually the home directory of $user
  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.sh start” 改为 “seahub.sh start-fastcgi”

  • 完成。如果你更新了你的 seafile 服务,不要忘记更新 script_path 的值。

RHEL/CentOS (run as service)

在 RHEL/CentOS 我们使用 /etc/init.d/ 脚本来实现 seafile/seahub 服务开机自启动。

创建文件 /etc/sysconfig/seafile

  1. # Change the value of "user" to your linux user name
  2. user=haiwen
  3. # Change the value of "seafile_dir" to your path of seafile installation
  4. # usually the home directory of $user
  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. # Change the value of fastcgi to true if fastcgi is to be used
  10. fastcgi=false
  11. # Set the port of fastcgi, default is 8000. Change it if you need different.
  12. 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. #
  37. # Write a polite log message with date and time
  38. #
  39. echo -e "n n About to perform $1 for seafile at `date -Iseconds` n " >> ${seafile_init_log}
  40. # See how we were called.
  41. case "$1" in
  42. start)
  43. start
  44. ;;
  45. stop)
  46. stop
  47. ;;
  48. restart|reload)
  49. stop
  50. start
  51. RETVAL=$?
  52. ;;
  53. *)
  54. echo $"Usage: $0 {start|stop|restart}"
  55. RETVAL=3
  56. esac
  57. 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 seahub: "
  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. #
  42. # Write a polite log message with date and time
  43. #
  44. echo -e "n n About to perform $1 for seahub at `date -Iseconds` n " >> ${seahub_init_log}
  45. # See how we were called.
  46. case "$1" in
  47. start)
  48. start
  49. ;;
  50. stop)
  51. stop
  52. ;;
  53. restart|reload)
  54. stop
  55. start
  56. RETVAL=$?
  57. ;;
  58. *)
  59. echo $"Usage: $0 {start|stop|restart}"
  60. RETVAL=3
  61. esac
  62. 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