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.

83 lines
1.7 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
  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. ln -s /etc/i2pd/tunnels.conf "$data_dir/tunnels.conf"
  25. if [ -n "$addressbook_dir" ]; then
  26. if [ ! -d "$addressbook_dir" ]; then
  27. mkdir -p "$addressbook_dir"
  28. fi
  29. ln -s "$addressbook_dir" "$data_dir/addressbook"
  30. fi
  31. fi
  32. ## We need permissions
  33. chown "$USER:$GROUP" "$data_dir"
  34. chown "$USER:$GROUP" "$addressbook_dir"
  35. touch "$PIDFILE"
  36. chown "$USER:adm" "$PIDFILE"
  37. procd_open_instance
  38. procd_set_param command "$PROG" --service --conf="$CONFFILE" --pidfile "$PIDFILE"
  39. ## Don't know about i2pd user's HOME
  40. procd_set_param env "HOME=$DATADIR"
  41. procd_set_param limits nofile=4096
  42. procd_set_param stdout 1
  43. procd_set_param stderr 1
  44. procd_set_param user "$USER"
  45. procd_set_param pidfile "$PIDFILE"
  46. procd_close_instance
  47. }
  48. start_service() {
  49. local instance="$1"
  50. local instance_found=0
  51. config_cb() {
  52. local type="$1"
  53. local name="$2"
  54. if [ "$type" = "i2pd" ]; then
  55. if [ -n "$instance" ] && [ "$instance" = "$name" ]; then
  56. instance_found=1
  57. fi
  58. fi
  59. }
  60. config_load i2pd
  61. if [ -n "$instance" ]; then
  62. [ "$instance_found" -gt 0 ] || return
  63. i2pd_start "$instance"
  64. else
  65. config_foreach i2pd_start i2pd
  66. fi
  67. }