seafile.init 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/bash /etc/rc.common
  2. START=98
  3. APP=seafile
  4. EXTRA_HELP=" setup Runs the setup script
  5. create_admin Creates the administrative login
  6. reset_admin Alias to create_admin"
  7. EXTRA_COMMANDS="setup create_admin reset_admin"
  8. TOPDIR=/usr/share/seafile
  9. default_ccnet_conf_dir=${TOPDIR}/ccnet
  10. central_config_dir=${TOPDIR}/conf
  11. seaf_controller=/usr/bin/seafile-controller
  12. function validate_ccnet_conf_dir () {
  13. if [[ ! -d ${default_ccnet_conf_dir} ]]; then
  14. echo "Error: there is no ccnet config directory."
  15. echo "Have you run \"/etc/init.d/seafile setup\"?"
  16. echo ""
  17. exit 1
  18. fi
  19. }
  20. function validate_central_conf_dir () {
  21. if [[ ! -d ${central_config_dir} ]]; then
  22. echo "Error: there is no conf/ directory."
  23. echo "Have you run \"/etc/init.d/seafile setup\"?"
  24. echo ""
  25. exit 1
  26. fi
  27. }
  28. function read_seafile_data_dir () {
  29. seafile_ini=${default_ccnet_conf_dir}/seafile.ini
  30. if [[ ! -f ${seafile_ini} ]]; then
  31. echo "Error: ${seafile_ini} not found."
  32. exit 1
  33. fi
  34. seafile_data_dir=$(cat "${seafile_ini}")
  35. if [[ ! -d ${seafile_data_dir} ]]; then
  36. echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
  37. echo "Please check it first, or create this directory yourself."
  38. echo ""
  39. exit 1
  40. fi
  41. }
  42. function test_config() {
  43. if ! ${seaf_controller} --test \
  44. -c "${default_ccnet_conf_dir}" \
  45. -d "${seafile_data_dir}" \
  46. -F "${central_config_dir}" ; then
  47. exit 1
  48. fi
  49. }
  50. function check_component_running() {
  51. name=$1
  52. cmd=$2
  53. if pid=$(pgrep -f "$cmd" 2>/dev/null); then
  54. return 1
  55. fi
  56. }
  57. function validate_already_running () {
  58. check_component_running "seafile-controller" "seafile-controller -F ${central_config_dir}" || return 1
  59. check_component_running "ccnet-server" "ccnet-server -F ${central_config_dir}" || return 1
  60. check_component_running "seaf-server" "seaf-server -F ${central_config_dir}" || return 1
  61. check_component_running "fileserver" "fileserver -F ${central_config_dir}" || return 1
  62. check_component_running "seafdav" "wsgidav.server.run_server" || return 1
  63. }
  64. function start_seafile_server () {
  65. if ! validate_already_running; then
  66. if [[ "$name" == "seafile-controller" ]]; then
  67. echo "Seafile already running."
  68. else
  69. echo "Error: component [$name] is already running. Please try stopping it manually by running \"kill $pid\"."
  70. echo "To force killing the process, use \"kill -9 $pid\"."
  71. fi
  72. exit 1
  73. fi
  74. validate_central_conf_dir
  75. validate_ccnet_conf_dir
  76. read_seafile_data_dir
  77. test_config
  78. echo "Starting seafile server, please wait ..."
  79. ${seaf_controller} \
  80. -F "${central_config_dir}" \
  81. -c "${default_ccnet_conf_dir}" \
  82. -d "${seafile_data_dir}"
  83. sleep 3
  84. # check if seafile server started successfully
  85. if ! pgrep -f "seafile-controller -F ${central_config_dir}" 2>/dev/null 1>&2; then
  86. echo "Failed to start seafile server"
  87. exit 1
  88. fi
  89. echo "Seafile server started"
  90. echo
  91. }
  92. function stop_seafile_server () {
  93. if ! pgrep -f "seafile-controller -F ${central_config_dir}" 2>/dev/null 1>&2; then
  94. echo "Seafile server not running"
  95. else
  96. echo "Stopping seafile server ..."
  97. pkill -SIGTERM -f "seafile-controller -F ${central_config_dir}"
  98. pkill -f "ccnet-server -F ${central_config_dir}"
  99. pkill -f "seaf-server -F ${central_config_dir}"
  100. pkill -f "fileserver -F ${central_config_dir}"
  101. pkill -f "soffice.*--invisible --nocrashreport"
  102. pkill -f "wsgidav.server.run_server"
  103. retry=1
  104. while ! validate_already_running && [ $retry -lt 60 ]; do sleep 1; ((retry++)); done
  105. if ! validate_already_running; then
  106. echo "Error: [$name] component is still running. Please try stopping it manually by running \"kill $pid\"."
  107. echo "To force killing the process, use \"kill -9 $pid\"."
  108. fi
  109. fi
  110. }
  111. function restart_seafile_server () {
  112. stop_seafile_server
  113. start_seafile_server
  114. }
  115. function start() {
  116. start_seafile_server
  117. }
  118. function stop() {
  119. stop_seafile_server
  120. }
  121. function restart() {
  122. restart_seafile_server
  123. }
  124. function setup() {
  125. cd "$TOPDIR" && \
  126. /usr/bin/seafile-admin setup
  127. }
  128. function create_admin() {
  129. cd "$TOPDIR" && \
  130. /usr/bin/seafile-admin create-admin
  131. }
  132. function reset_admin() {
  133. create_admin
  134. }