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.

81 lines
1.8 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2017 OpenWrt.org
  3. # Copyright (C) 2021-2022 PurpleI2P team
  4. USE_PROCD=1
  5. START=90
  6. STOP=10
  7. # default params
  8. PROG=/usr/sbin/i2pd
  9. USER="i2pd"
  10. GROUP="i2pd"
  11. PIDFILE=/var/run/i2pd.pid
  12. DATADIR=/var/lib/i2pd
  13. CONFFILE=/etc/i2pd/i2pd.conf
  14. start_instance() {
  15. local data_dir netdb_dir addressbook_dir cfg="$1"
  16. config_get data_dir "$cfg" data_dir "$DATADIR"
  17. config_get netdb_dir "$cfg" netdb_dir
  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. ln -s /usr/share/i2pd/certificates "$data_dir/certificates"
  23. ln -s /etc/i2pd/i2pd.conf "$data_dir/i2pd.conf"
  24. ln -s /etc/i2pd/tunnels.conf "$data_dir/tunnels.conf"
  25. ln -s /etc/i2pd/tunnels.d "$data_dir/tunnels.d"
  26. fi
  27. if [ -n "$netdb_dir" ]; then
  28. if [ ! -d "$netdb_dir" ]; then
  29. mkdir -p "$netdb_dir"
  30. fi
  31. ln -s "$netdb_dir" "$data_dir/netDb"
  32. fi
  33. if [ -n "$addressbook_dir" ]; then
  34. if [ ! -d "$addressbook_dir" ]; then
  35. mkdir -p "$addressbook_dir"
  36. fi
  37. ln -s "$addressbook_dir" "$data_dir/addressbook"
  38. fi
  39. ## We need permissions
  40. chown "$USER:$GROUP" "$data_dir"
  41. if [ -n "$netdb_dir" ]; then
  42. chown "$USER:$GROUP" "$netdb_dir"
  43. fi
  44. if [ -n "$addressbook_dir" ]; then
  45. chown "$USER:$GROUP" "$addressbook_dir"
  46. fi
  47. touch "$PIDFILE"
  48. chown "$USER:adm" "$PIDFILE"
  49. procd_open_instance
  50. procd_set_param command "$PROG" --datadir="$data_dir" --conf="$CONFFILE" --pidfile "$PIDFILE"
  51. ## Don't know about i2pd user's HOME
  52. procd_set_param env "HOME=$data_dir"
  53. procd_set_param limits nofile=4096
  54. procd_set_param stdout 1
  55. procd_set_param stderr 1
  56. procd_set_param user "$USER"
  57. procd_set_param pidfile "$PIDFILE"
  58. procd_close_instance
  59. }
  60. start_service() {
  61. config_load "i2pd"
  62. config_foreach start_instance "i2pd"
  63. }
  64. reload_service() {
  65. procd_send_signal i2pd
  66. }