Advertisement
Guest User

Untitled

a guest
Aug 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # This stuff will be ignored by systems that don't use chkconfig.
  4. # chkconfig: 345 87 13
  5. # description: H2 database
  6. # pidfile: /opt/H2/bin/h2.pid
  7. # config:
  8.  
  9. ### BEGIN INIT INFO
  10. # Provides: H2-Server
  11. # Required-Start:
  12. # Required-Stop:
  13. # Default-Start: 3 5
  14. # Default-Stop: 0 1 2 6
  15. # Short-Description: H2-Server
  16. # Description: H2 database service
  17. ### END INIT INFO
  18.  
  19. # Starts and stops the h2 database
  20.  
  21. # Some general variables
  22. H2_VERSION=1.4.192 # Important! Set your version!
  23. H2_HOME=/opt/h2
  24. #JVM_OPTS="-DfunctionsInSchema=true"
  25. JVM_OPTS=""
  26.  
  27. # starts h2 server
  28. h2_start () {
  29.  
  30. if [ -e $H2_HOME/bin/h2.pid ]; then
  31. echo "H2 is still running"
  32. exit 1
  33. fi
  34.  
  35. cd $H2_HOME/bin
  36.  
  37. # this will start h2 server with allowed tcp connection
  38. # you can find more info in h2 tutorials
  39. java -Xms256m -Xmx768m -cp h2-$H2_VERSION.jar $JVM_OPTS org.h2.tools.Server -tcp -tcpAllowOthers -web -webAllowOthers -baseDir $H2_HOME/db $1 > $H2_HOME/h2.log 2>&1 &
  40.  
  41. echo $! > $H2_HOME/bin/h2.pid
  42. sleep 3
  43. echo "H2-$H2_VERSION started. Setting multithreaded"
  44.  
  45. # Just set multi threaded on my database with name kemuri
  46. java -cp h2-$H2_VERSION.jar $JVM_OPTS org.h2.tools.Shell -url "jdbc:h2:tcp://localhost/kemuri" -user kemuri -password kemuri -sql "SET MULTI_THREADED 1"
  47.  
  48. }
  49.  
  50. # stops h2
  51. h2_stop () {
  52. if [ -e $H2_HOME/bin/h2.pid ]; then
  53. PID=$(cat $H2_HOME/bin/h2.pid)
  54. kill -TERM ${PID}
  55. echo SIGTERM sent to process ${PID}
  56. rm $H2_HOME/bin/h2.pid
  57. else
  58. echo File $H2_HOME/bin/h2.pid not found!
  59. fi
  60. }
  61.  
  62. # Just to remove pid file in case you killed h2 manually
  63. # and want to start it by script, but he thinks
  64. # that h2 is already running
  65. h2_zap () {
  66. rm $H2_HOME/bin/h2.pid
  67. }
  68.  
  69. # Backups specified database to a given path
  70. backup () {
  71. echo Backing up database to $1
  72. cd $H2_HOME/bin
  73.  
  74. java -cp h2-$H2_VERSION.jar $JVM_OPTS org.h2.tools.Script -url "jdbc:h2:tcp://localhost/kemuri" -user kemuri -password kemuri -script "$1" -options compression zip
  75.  
  76. }
  77.  
  78. # Restores specified database from the given path
  79. restore () {
  80. echo Restoring database from $1
  81. cd $H2_HOME/bin
  82.  
  83. java -cp h2-$H2_VERSION.jar $JVM_OPTS org.h2.tools.RunScript -url "jdbc:h2:tcp://localhost/kemuri;create=true" -user kemuri -password kemuri -script "$1" -continueOnError -options compression zip
  84.  
  85. }
  86.  
  87. case "$1" in
  88. init)
  89. h2_start
  90. ;;
  91. start)
  92. h2_start -ifExists
  93. ;;
  94. stop)
  95. h2_stop
  96. ;;
  97. zap)
  98. h2_zap
  99. ;;
  100. restart)
  101. h2_stop
  102. sleep 5
  103. h2_start -ifExists
  104. ;;
  105. backup)
  106. backup $2
  107. ;;
  108. restore)
  109. restore $2
  110. ;;
  111. *)
  112. echo "Usage: /etc/init.d/h2 {init|start|stop|restart|backup |restore }"
  113. exit 1
  114. ;;
  115. esac
  116.  
  117. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement