Guest User

Untitled

a guest
Nov 25th, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: bitcoin-cpuminer
  4. # Required-Start: $network $local_fs
  5. # Required-Stop:
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: BitCoin CPUminer
  9. # Description: This application uses idle cpu time (for as much
  10. # as possible) to mine for bitcoins.
  11. ### END INIT INFO
  12.  
  13. # Original Author: Tim Stoop <bitcoin-cpuminer@timstoop.nl>
  14.  
  15. # Edited: Sungjin Han <meinside@gmail.com>
  16. #
  17. # for running cpuminer on linux (debian) servers:
  18. #
  19. # 1. install essential packages
  20. #
  21. # $ sudo apt-get -y install gcc gcc-4.5 g++ g++-4.5 libstdc++6-4.5-dev libpcre3-dev libcurl3-dev make automake less git
  22. #
  23. # 2. clone cpuminer's repository
  24. #
  25. # ex)
  26. #
  27. # $ git clone git://github.com/pooler/cpuminer.git
  28. #
  29. # 3. build cpuminer
  30. #
  31. # ex)
  32. #
  33. # $ cd cpuminer
  34. # $ ./autogen.sh
  35. # $ ./configure CFLAGS="-O3"
  36. # $ make
  37. #
  38. # 4. copy this script to /etc/init.d/
  39. #
  40. # $ sudo cp bitcoin-cpuminer /etc/init.d/
  41. # $ sudo chmod +x /etc/init.d/bitcoin-cpuminer
  42. #
  43. # 5. edit the init script (marked as 'XXX')
  44. #
  45. # $ sudo vi /etc/init.d/bitcoin-cpuminer
  46. #
  47. # 6. run as service
  48. #
  49. # $ sudo update-rc.d bitcoin-cpuminer defaults
  50. #
  51. # 7. reboot or start the service manually
  52. #
  53. # $ sudo shutdown -r
  54. #
  55. # or
  56. #
  57. # $ sudo service bitcoin-cpuminer start
  58. #
  59.  
  60. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  61. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  62. DESC=bitcoin-cpuminer
  63. NAME=minerd
  64. DAEMON=/usr/bin/minerd # XXX - edit this: path to the minerd binary file
  65. DAEMON_OPTS="-o [URL] -u [USER] -p [PASSWORD]" # XXX - edit this: minerd options
  66. PIDFILE=/var/run/$NAME.pid
  67. SCRIPTNAME=/etc/init.d/$DESC
  68. USER=bitminer # XXX - edit this
  69.  
  70. # Exit if the package is not installed
  71. [ -x $DAEMON ] || exit 0
  72.  
  73. # Read configuration variable file if it is present
  74. [ -r /etc/default/$DESC ] && . /etc/default/$DESC
  75.  
  76. # Load the VERBOSE setting and other rcS variables
  77. . /lib/init/vars.sh
  78.  
  79. # Define LSB log_* functions.
  80. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  81. . /lib/lsb/init-functions
  82.  
  83. #
  84. # Function that starts the daemon/service
  85. #
  86. do_start()
  87. {
  88. # Return
  89. # 0 if daemon has been started
  90. # 1 if daemon was already running
  91. # 2 if daemon could not be started
  92. start-stop-daemon --chuid $USER --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  93. || return 1
  94. start-stop-daemon --background --chuid $USER --start --quiet --nicelevel 10 \
  95. --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \
  96. $DAEMON_OPTS \
  97. || return 2
  98. # Add code here, if necessary, that waits for the process to be ready
  99. # to handle requests from services started subsequently which depend
  100. # on this one. As a last resort, sleep for some time.
  101. }
  102.  
  103. #
  104. # Function that stops the daemon/service
  105. #
  106. do_stop()
  107. {
  108. # Return
  109. # 0 if daemon has been stopped
  110. # 1 if daemon was already stopped
  111. # 2 if daemon could not be stopped
  112. # other if a failure occurred
  113. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  114. RETVAL="$?"
  115. [ "$RETVAL" = 2 ] && return 2
  116. # Wait for children to finish too if this is a daemon that forks
  117. # and if the daemon is only ever run from this initscript.
  118. # If the above conditions are not satisfied then add some other code
  119. # that waits for the process to drop all resources that could be
  120. # needed by services started subsequently. A last resort is to
  121. # sleep for some time.
  122. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  123. [ "$?" = 2 ] && return 2
  124. # Many daemons don't delete their pidfiles when they exit.
  125. rm -f $PIDFILE
  126. return "$RETVAL"
  127. }
  128.  
  129. #
  130. # Function that sends a SIGHUP to the daemon/service
  131. #
  132. do_reload() {
  133. #
  134. # If the daemon can reload its configuration without
  135. # restarting (for example, when it is sent a SIGHUP),
  136. # then implement that here.
  137. #
  138. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  139. return 0
  140. }
  141.  
  142. case "$1" in
  143. start)
  144. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
  145. do_start
  146. case "$?" in
  147. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  148. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  149. esac
  150. ;;
  151. stop)
  152. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  153. do_stop
  154. case "$?" in
  155. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  156. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  157. esac
  158. ;;
  159. status)
  160. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  161. ;;
  162. #reload|force-reload)
  163. #
  164. # If do_reload() is not implemented then leave this commented out
  165. # and leave 'force-reload' as an alias for 'restart'.
  166. #
  167. #log_daemon_msg "Reloading $DESC" "$NAME"
  168. #do_reload
  169. #log_end_msg $?
  170. #;;
  171. restart|force-reload)
  172. #
  173. # If the "reload" option is implemented then remove the
  174. # 'force-reload' alias
  175. #
  176. log_daemon_msg "Restarting $DESC" "$NAME"
  177. do_stop
  178. case "$?" in
  179. 0|1)
  180. do_start
  181. case "$?" in
  182. 0) log_end_msg 0 ;;
  183. 1) log_end_msg 1 ;; # Old process is still running
  184. *) log_end_msg 1 ;; # Failed to start
  185. esac
  186. ;;
  187. *)
  188. # Failed to stop
  189. log_end_msg 1
  190. ;;
  191. esac
  192. ;;
  193. *)
  194. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  195. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  196. exit 3
  197. ;;
  198. esac
  199.  
  200. :
Add Comment
Please, Sign In to add comment