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.

79 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. [ -d "$data_dir" ] || {
  22. mkdir -p "$data_dir"
  23. chown "$USER:$GROUP" "$data_dir"
  24. ln -s /usr/share/i2pd/certificates "$data_dir/certificates"
  25. [ -n "$addressbook_dir" ] && {
  26. [ -d "$addressbook_dir" ] || mkdir -p "$addressbook_dir"
  27. chown "$USER:$GROUP" "$addressbook_dir"
  28. ln -s "$addressbook_dir" "$data_dir/addressbook"
  29. }
  30. }
  31. ## We need permissions
  32. touch "$PIDFILE"
  33. chown "$USER:adm" "$PIDFILE"
  34. procd_open_instance
  35. procd_set_param command "$PROG" --service --conf="$CONFFILE" --pidfile "$PIDFILE"
  36. ## Don't know about i2pd user's HOME
  37. procd_set_param env "HOME=$DATADIR"
  38. ## For debugging, provide about 512 MB on external storage for coredump and adjust /proc/sys/kernel/core_pattern
  39. # echo "/tmp/coredumps/core.%e.%p.%s.%t" > /proc/sys/kernel/core_pattern
  40. # procd_set_param limits core="unlimited unlimited"
  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. [ "$type" = "i2pd" ] && [ -n "$instance" ] && [ "$instance" = "$name" ] && instance_found=1
  55. }
  56. config_load i2pd
  57. if [ -n "$instance" ]; then
  58. [ "$instance_found" -gt 0 ] || return
  59. i2pd_start "$instance"
  60. else
  61. config_foreach i2pd_start i2pd
  62. fi
  63. }