rc.boinc.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. # rc.boinc - BOINC startup/control script for Slackware Linux
  3. #
  4. # Copyright 2022 Edward Koenig, Vancouver, WA, USA
  5. # All rights reserved.
  6. #
  7. # Redistribution and use of this script, with or without modification, is
  8. # permitted provided that the following conditions are met:
  9. #
  10. # 1. Redistributions of this script must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. #
  13. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
  14. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  16. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  21. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. BOINC_DIR=/var/lib/boinc_data # directory of boinc files
  24. BOINC_BIN=boinc # name of the boinc binary
  25. BOINC_USER=root # user that will run boinc process
  26. BOINC_OPTIONS="--dir $BOINC_DIR --redirectio"
  27. # "--dir $BOINC_DIR --daemon" will send logs syslog instead of
  28. # stdoutdae.txt and stderrdae.txt
  29. boinc_status() {
  30. if ( ps -ef | grep "$BOINC_BIN$" > /dev/null 2>&1 ); then
  31. return 0
  32. else
  33. return 3
  34. fi
  35. }
  36. boinc_start() {
  37. boinc_status
  38. if [ $? = 0 ]; then
  39. echo "BOINC is already running"
  40. exit 1
  41. fi
  42. if [ ! -d $BOINC_DIR ]; then
  43. echo "ERROR: $BOINC_DIR does not exist"
  44. exit 1
  45. elif [ ! -x BOINC_BIN ]; then
  46. echo "ERROR: BOINC_BIN does not exist or not executable"
  47. exit 1
  48. fi
  49. echo "Starting BOINC client"
  50. su - $BOINC_USER -c "cd $BOINC_DIR; exec /usr/bin/$BOINC_BIN $BOINC_OPTIONS" &
  51. }
  52. boinc_stop() {
  53. echo "Stopping BOINC client"
  54. killall $BOINC_BIN
  55. }
  56. boinc_restart() {
  57. echo "Restarting BOINC client"
  58. boinc_status
  59. if [ $? = 0 ]; then
  60. boinc_stop
  61. sleep 3
  62. boinc_start
  63. else
  64. boinc_start
  65. fi
  66. }
  67. case "$1" in
  68. start)
  69. boinc_start
  70. exit 0
  71. ;;
  72. stop)
  73. boinc_stop
  74. exit 0
  75. ;;
  76. restart)
  77. boinc_restart
  78. exit 0
  79. ;;
  80. status)
  81. boinc_status
  82. if [ $? = 0 ]; then
  83. echo "BOINC is running"
  84. else
  85. echo "BOINC is not running"
  86. fi
  87. ;;
  88. *)
  89. echo "Usage: $0 start|stop|restart|status"
  90. exit 1
  91. ;;
  92. esac