You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2019 Elon Huang <elonhhuang@gmail.com>
  3. USE_PROCD=1
  4. START=95
  5. STOP=10
  6. APP="rclone"
  7. CONFIGURATION="rclone"
  8. _info() {
  9. logger -p daemon.info -t "$APP" "$*"
  10. }
  11. _err() {
  12. logger -p daemon.err -t "$APP" "$*"
  13. }
  14. start_service() {
  15. config_load "${CONFIGURATION}"
  16. local enabled
  17. config_get_bool enabled global enabled
  18. if [ "$enabled" -ne "1" ]; then
  19. _info 'Instance "rclone" is disabled.'
  20. return 1
  21. else
  22. _info 'Instance "rclone" is starting.'
  23. fi
  24. local config_path log_path
  25. local addr addr_type port
  26. local username password
  27. local proxy_enable proxy_addr
  28. config_get config_path config config_path
  29. config_get log_path log path
  30. config_get addr_type config addr_type
  31. config_get port config port
  32. config_get username config username
  33. config_get password config password
  34. config_get_bool proxy_enable proxy enabled
  35. config_get proxy_addr proxy proxy_addr
  36. if [ "${addr_type}" = "local" ]; then
  37. addr="$(uci get network.loopback.ipaddr)"
  38. elif [ "${addr_type}" = "lan" ]; then
  39. addr="$(uci get network.lan.ipaddr)"
  40. else
  41. addr=""
  42. fi
  43. local config_dir="${config_path%/*}"
  44. [ -d "$config_dir" ] || mkdir -p "$config_dir"
  45. touch "${config_path}"
  46. chown rclone "${config_path}"
  47. [ -d "/lib/upgrade/keep.d" ] || mkdir -p "/lib/upgrade/keep.d/"
  48. echo "$config_path" > "/lib/upgrade/keep.d/luci-app-rclone"
  49. local log_dir="${log_path%/*}"
  50. [ -d "$log_dir" ] || mkdir -p "$log_dir"
  51. chown -R rclone:rclone "$log_dir"
  52. procd_open_instance
  53. procd_set_param command /usr/bin/$APP rcd -vv
  54. procd_append_param command "--rc-addr=$addr:$port"
  55. procd_append_param command "--rc-user=$username" "--rc-pass=$password"
  56. procd_append_param command "--config=$config_path"
  57. procd_append_param command "--rc-allow-origin=*"
  58. procd_append_param command "--log-file=${log_path}"
  59. if [ "${proxy_enable}" -eq "1" ]; then
  60. procd_set_param env all_proxy="$proxy_addr" https_proxy="$proxy_addr" http_proxy="$proxy_addr"
  61. procd_append_param env ALL_PROXY="$proxy_addr" HTTPS_PROXY="$proxy_addr" HTTP_PROXY="$proxy_addr"
  62. fi
  63. procd_set_param stdout 1
  64. procd_set_param stderr 1
  65. # procd_set_param pidfile /var/run/rclone.pid
  66. procd_set_param respawn
  67. procd_set_param user rclone
  68. procd_set_param group rclone
  69. procd_close_instance
  70. }
  71. reload_service() {
  72. stop
  73. start
  74. }
  75. service_triggers() {
  76. procd_add_reload_trigger "rclone"
  77. }