Start Seafile at System Bootup

For systems running systemd

  • For example Debian 8 and newer, Linux Ubuntu 15.04 and newer

Create systemd service files, change ${seafile_dir} to your
seafile installation location and seafile to user, who runs
seafile (if appropriate). Then you need to reload systemd’s daemons:
systemctl daemon-reload.

Create systemd service file /etc/systemd/system/seafile.service

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

The content of the file is:

  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=forking
  7. ExecStart=${seafile_dir}/seafile-server-latest/seafile.sh start
  8. ExecStop=${seafile_dir}/seafile-server-latest/seafile.sh stop
  9. User=seafile
  10. Group=seafile
  11. [Install]
  12. WantedBy=multi-user.target

Create systemd service file /etc/systemd/system/seahub.service

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

The content of the file is (please dont forget to change it if you want to run fastcgi):

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

Create systemd service file /etc/systemd/system/seafile-client.service (optional)

You need to create this service file only if you have seafile
console client and you want to run it on system boot.

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

The content of the file is:

  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

Enable service start on system boot

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

For systems using another init system than systemd

Ubuntu 14.10 and older

On Ubuntu without systemd we make use of the
/etc/init.d/
scripts to start seafile/seahub at system boot.

Create a script /etc/init.d/seafile-server

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

The content of this script is: (You need to modify the value of user
and seafile_dir accordingly)

  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 false if fastcgi is not used
  20. fastcgi=true
  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

Note: If you are using local mysql server, please replace # Required-Start: $remote_fs $syslog with # Required-Start: $remote_fs $syslog mysql.

Make the seafile-sever script executable

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

Add seafile-server to rc.d

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

Note: Don’t forget to update the value of script_path later if you update
your seafile server.

Other Debian based Distributions

Create a script /etc/init.d/seafile-server

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

The content of this script is: (You need to modify the value of user
and seafile_dir accordingly)

  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

Note:

  1. If you want to start seahub in fastcgi, just change the fastcgi
    variable to true
  2. If you deployed Seafile with MySQL, append “mysql” to the
    Required-Start line:
  1. # Required-Start: $local_fs $remote_fs $network mysql

Add Directory for Logfiles

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

Make the seafile-sever script executable

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

Add seafile-server to rc.d

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

Done

Don’t forget to update the value of seafile_dir later if you update
your seafile server.

RHEL/CentOS

On RHEL/CentOS, the script
/etc/rc.local
is executed by the system at bootup, so we start seafile/seahub there.

  • Locate your python executable (python 2.6 or 2.7)
  1. which python2.6 # or "which python2.7"
  • In /etc/rc.local, add the directory of python2.6(2.7) to PATH,
    and add the seafile/seahub start command
  1. `
  2. # Assume the python 2.6(2.7) executable is in "/usr/local/bin"
  3. PATH=$PATH:/usr/local/bin/
  4. # Change the value of "user" to your linux user name
  5. user=haiwen
  6. # Change the value of "seafile_dir" to your path of seafile installation
  7. # usually the home directory of $user
  8. seafile_dir=/data/haiwen
  9. script_path=${seafile_dir}/seafile-server-latest
  10. sudo -u ${user} ${script_path}/seafile.sh start > /tmp/seafile.init.log 2>&1
  11. sudo -u ${user} ${script_path}/seahub.sh start > /tmp/seahub.init.log 2>&1

Note: If you want to start seahub in fastcgi, just change the
“seahub.sh start” in the last line above to “seahub.sh
start-fastcgi”

  • Done. Don’t forget to update the value of seafile_dir later if
    you update your seafile server.

RHEL/CentOS (run as service)

On RHEL/CentOS we make use of the /etc/init.d/ scripts to start
seafile/seahub at system boot as service.

Create a file /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

Create a script /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

Create a script /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

Next, enable services:

  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

and run:

  1. service seafile start
  2. service seahub start