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.

85 lines
1.8 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2017 OpenWrt.org
  3. USE_PROCD=1
  4. START=90
  5. STOP=10
  6. # default params
  7. PROG=/usr/sbin/i2pd
  8. USER="i2pd"
  9. GROUP="i2pd"
  10. PIDFILE=/var/run/i2pd.pid
  11. DATADIR=/var/lib/i2pd
  12. CONFFILE=/etc/i2pd/i2pd.conf
  13. . /lib/functions.sh
  14. i2pd_start() {
  15. local cfg="$1"
  16. local data_dir
  17. local addressbook_dir
  18. config_get data_dir "$cfg" data_dir "$DATADIR"
  19. config_get addressbook_dir "$cfg" addressbook_dir
  20. ## Setting up data dir
  21. if [ ! -d "$data_dir" ]; then
  22. mkdir -p "$data_dir"
  23. ln -s /usr/share/i2pd/certificates "$data_dir/certificates"
  24. if [ -n "$addressbook_dir" ]; then
  25. if [ ! -d "$addressbook_dir" ]; then
  26. mkdir -p "$addressbook_dir"
  27. fi
  28. ln -s "$addressbook_dir" "$data_dir/addressbook"
  29. fi
  30. fi
  31. ## We need permissions
  32. chown "$USER:$GROUP" "$data_dir"
  33. chown "$USER:$GROUP" "$addressbook_dir"
  34. touch "$PIDFILE"
  35. chown "$USER:adm" "$PIDFILE"
  36. procd_open_instance
  37. procd_set_param command "$PROG" --service --conf="$CONFFILE" --pidfile "$PIDFILE"
  38. ## Don't know about i2pd user's HOME
  39. procd_set_param env "HOME=$DATADIR"
  40. ## For debugging, provide about 512 MB on external storage for coredump and adjust /proc/sys/kernel/core_pattern
  41. # echo "/tmp/coredumps/core.%e.%p.%s.%t" > /proc/sys/kernel/core_pattern
  42. # procd_set_param limits core="unlimited unlimited"
  43. procd_set_param limits nofile=4096
  44. procd_set_param stdout 1
  45. procd_set_param stderr 1
  46. procd_set_param user "$USER"
  47. procd_set_param pidfile "$PIDFILE"
  48. procd_close_instance
  49. }
  50. start_service() {
  51. local instance="$1"
  52. local instance_found=0
  53. config_cb() {
  54. local type="$1"
  55. local name="$2"
  56. if [ "$type" = "i2pd" ]; then
  57. if [ -n "$instance" ] && [ "$instance" = "$name" ]; then
  58. instance_found=1
  59. fi
  60. fi
  61. }
  62. config_load i2pd
  63. if [ -n "$instance" ]; then
  64. [ "$instance_found" -gt 0 ] || return
  65. i2pd_start "$instance"
  66. else
  67. config_foreach i2pd_start i2pd
  68. fi
  69. }