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.

44 lines
1014 B

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2021-2022 Gerald Kerma <gandalf@gk2.net>
  3. START=99
  4. USE_PROCD=1
  5. NAME=crowdsec
  6. PROG=/usr/bin/crowdsec
  7. CONFIG=/etc/crowdsec/config.yaml
  8. RUNCONFDIR=/srv/crowdsec/data
  9. VARCONFIGDIR=/var/etc/crowdsec
  10. VARCONFIG=/var/etc/crowdsec/config.yaml
  11. service_triggers() {
  12. procd_add_reload_trigger crowdsec
  13. }
  14. init_config() {
  15. config_load crowdsec
  16. config_get data_dir crowdsec data_dir "${RUNCONFDIR}"
  17. config_get db_path crowdsec db_path "${RUNCONFDIR}/crowdsec.db"
  18. # Create tmp dir & permissions if needed
  19. if [ ! -d "${VARCONFIGDIR}" ]; then
  20. mkdir -m 0755 -p "${VARCONFIGDIR}"
  21. fi;
  22. cp $CONFIG $VARCONFIG
  23. sed -i "s,^\(\s*data_dir\s*:\s*\).*\$,\1$data_dir," $VARCONFIG
  24. sed -i "s,^\(\s*db_path\s*:\s*\).*\$,\1$db_path," $VARCONFIG
  25. # Create data dir & permissions if needed
  26. if [ ! -d "${RUNCONFDIR}" ]; then
  27. mkdir -m 0755 -p "${RUNCONFDIR}"
  28. fi;
  29. }
  30. start_service() {
  31. init_config
  32. procd_open_instance
  33. procd_set_param command "$PROG" -c "$VARCONFIG"
  34. procd_close_instance
  35. }