fhem.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh
  2. #
  3. #
  4. HOME='/var/packages/FHEM/target'
  5. PERL=/usr/bin/perl
  6. KMOD=/var/packages/usb-driver-kernel
  7. PATH=$HOME:$PERL:$PATH
  8. export PATH
  9. fhem_BIN=${HOME}/fhem.pl
  10. test -x ${fhem_BIN} || { echo "${fhem_BIN} not installed";
  11. if [ "$1" = "stop" ]; then exit 0;
  12. else exit 5; fi; }
  13. # Check for existence of needed config file and read it
  14. fhem_CONFIG=${HOME}/fhem.cfg
  15. test -r ${fhem_CONFIG} || { echo "${fhem_CONFIG} not existing";
  16. if [ "$1" = "stop" ]; then exit 0;
  17. else exit 6; fi; }
  18. fhem_LOG=/var/log/fhem-`date +"%Y-%m"`.log
  19. perl_BIN=`which perl`
  20. #
  21. case "$1" in
  22. start)
  23. echo "Starting fhem "
  24. if [ -d "${KMOD}" ]; then
  25. if [ ! -f "${KMOD}/enabled" ]; then
  26. ${KMOD}/scripts/start-stop-status start
  27. touch ${KMOD}/enabled && chmod 775 ${KMOD}/enabled
  28. fi
  29. fi
  30. ${perl_BIN} $fhem_BIN $fhem_CONFIG
  31. ;;
  32. stop)
  33. echo "Shutting down fhem "
  34. ${perl_BIN} $fhem_BIN 7072 shutdown
  35. ;;
  36. restart)
  37. $0 stop
  38. $0 start
  39. ;;
  40. status)
  41. echo -n "Checking for service fhem "
  42. ps|grep fhem.pl
  43. ;;
  44. log)
  45. test -r $fhem_LOG || { echo "$fhem_LOG not existing"; exit 0; }
  46. echo $fhem_LOG
  47. ;;
  48. *)
  49. echo "Usage: $0 {start|stop|status|restart|log}"
  50. exit 1
  51. ;;
  52. esac
  53. exit 0