cgminer.avalon2.init 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. APP=cgminer
  4. PID_FILE=/var/run/$APP.pid
  5. start() {
  6. local _pool1url
  7. local _pool1user
  8. local _pool1pw
  9. local _pool2url
  10. local _pool2user
  11. local _pool2pw
  12. local _pool3url
  13. local _pool3user
  14. local _pool3pw
  15. local _cf
  16. local _cv
  17. local _fan
  18. local _aa
  19. local _pb
  20. local _mo
  21. local _ntp_enable
  22. config_load cgminer
  23. config_get _pool1url default pool1url
  24. config_get _pool1user default pool1user
  25. config_get _pool1pw default pool1pw
  26. config_get _pool2url default pool2url
  27. config_get _pool2user default pool2user
  28. config_get _pool2pw default pool2pw
  29. config_get _pool3url default pool3url
  30. config_get _pool3user default pool3user
  31. config_get _pool3pw default pool3pw
  32. config_get _cf default chip_frequency
  33. config_get _cv default chip_voltage
  34. config_get _fan default fan
  35. config_get _aa default api_allow
  36. config_get _pb default pool_balance
  37. config_get _mo default more_options
  38. config_get _ntp_enable default ntp_enable
  39. if [ "$_pool1url" != "" -a "$_pool1user" != "" -a "$_pool1pw" != "" ]; then
  40. POOL1="-o $_pool1url -O $_pool1user:$_pool1pw"
  41. fi
  42. if [ "$_pool2url" != "" -a "$_pool2user" != "" -a "$_pool2pw" != "" ]; then
  43. POOL2="-o $_pool2url -O $_pool2user:$_pool2pw"
  44. fi
  45. if [ "$_pool3url" != "" -a "$_pool3user" != "" -a "$_pool3pw" != "" ]; then
  46. POOL3="-o $_pool3url -O $_pool3user:$_pool3pw"
  47. fi
  48. DEVS=`find /dev/ -type c -name "ttyUSB*" | sed 's/^/-S/' | sed ':a;N;$!ba;s/\n/ /g'`
  49. AVA2_OPTIONS=" --avalon2-fan $_fan --avalon2-freq $_cf --avalon2-voltage $_cv "
  50. PARAMS=" ${DEVS} $AVA2_OPTIONS $POOL1 $POOL2 $POOL3 $_pb --api-allow $_aa --api-listen $_mo "
  51. NTP_POOL="-p 0.openwrt.pool.ntp.org -p 1.openwrt.pool.ntp.org -p 3.openwrt.pool.ntp.org -p 4.openwrt.pool.ntp.org"
  52. ASIA="-p 1.cn.pool.ntp.org -p 3.asia.pool.ntp.org -p 2.asia.pool.ntp.org"
  53. # _ntp_enable: openwrt, asia, globle
  54. if [ "$_ntp_enable" == "asia" ]; then
  55. NTP_POOL="${ASIA}"
  56. fi
  57. if [ ! -f /tmp/cgminer-ntpd-done -a "$_ntp_enable" != "disable" ]; then
  58. while [ "$NTPD_RET" != "0" ]; do
  59. ntpd -d -n -q -N ${NTP_POOL}
  60. NTPD_RET=$?
  61. done
  62. touch /tmp/cgminer-ntpd-done
  63. fi
  64. # Make sure udevd run before cgminer start
  65. UDEVDCNT=`pidof udevd | wc -w`
  66. if [ "$UDEVDCNT" == "0" ]; then
  67. udevd --daemon
  68. fi
  69. start-stop-daemon -S -x $APP -p $PID_FILE -m -b -- $PARAMS
  70. }
  71. stop() {
  72. start-stop-daemon -K -n $APP -p $PID_FILE -s TERM
  73. }