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.

80 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. i2pd_start() {
  14. local cfg="$1"
  15. local data_dir
  16. local addressbook_dir
  17. config_get data_dir "$cfg" data_dir "$DATADIR"
  18. config_get addressbook_dir "$cfg" addressbook_dir
  19. ## Setting up data dir
  20. if [ ! -d "$data_dir" ] ; then
  21. mkdir -p "$data_dir"
  22. chown "$USER:$GROUP" "$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. chown "$USER:$GROUP" "$addressbook_dir"
  28. fi
  29. ln -s "$addressbook_dir" "$data_dir/addressbook"
  30. fi
  31. fi
  32. [ -d "$DATADIR" ] || ln -s "$data_dir" "$DATADIR"
  33. ## We need permissions
  34. touch "$PIDFILE"
  35. chown "$USER:adm" "$PIDFILE"
  36. chown "$USER:adm" "$CONFFILE"
  37. procd_open_instance
  38. procd_set_param command "$PROG" --service --conf="$CONFFILE" --pidfile "$PIDFILE"
  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. [ "$type" = "i2pd" -a -n "$instance" -a "$instance" = "$name" ] && instance_found=1
  57. }
  58. config_load i2pd
  59. if [ -n "$instance" ]; then
  60. [ "$instance_found" = 0 ] && return
  61. i2pd_start "$instance"
  62. else
  63. config_foreach i2pd_start i2pd
  64. fi
  65. }