virtualbox.init.vine 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #! /bin/sh
  2. #
  3. # virtualbox: Starts the VirtualBox kernel module
  4. #
  5. # chkconfig: 35 30 60
  6. # description: VirtualBox Linux kernel module
  7. #
  8. ### BEGIN INIT INFO
  9. # Provides: vboxdrv
  10. # Required-Start: $syslog
  11. # Required-Stop:
  12. # Default-Start: 3 5
  13. # Default-Stop:
  14. # Description: VirtualBox Linux kernel module
  15. # Should-Start: dkms
  16. ### END INIT INFO
  17. # Source function library.
  18. . /etc/init.d/functions
  19. prog="virtualbox"
  20. PROGNAME=VBoxSVC
  21. RETVAL=0
  22. running() {
  23. grep -q "^$1 " /proc/modules
  24. }
  25. start() {
  26. # Check if it is already running
  27. if ! running vboxdrv; then
  28. echo -n $"Starting $prog: "
  29. if ! modprobe vboxdrv > /dev/null 2>&1; then
  30. failure "Loading vboxdrv module:"
  31. return
  32. fi
  33. if ! modprobe vboxnetflt > /dev/null 2>&1; then
  34. failure "Loading vboxnetflt module:"
  35. return
  36. fi
  37. if ! modprobe vboxnetadp > /dev/null 2>&1; then
  38. failure "Loading vboxnetadp module:"
  39. return
  40. fi
  41. touch /var/lock/subsys/$PROGNAME
  42. success
  43. fi
  44. echo
  45. }
  46. stop() {
  47. echo -n "Stopping $prog: "
  48. if running vboxdrv; then
  49. if running vboxnetflt; then
  50. if ! rmmod vboxnetflt 2>/dev/null; then
  51. failure "Remove module vboxnetflt:"
  52. return
  53. fi
  54. fi
  55. if running vboxnetadp; then
  56. if ! rmmod vboxnetadp 2>/dev/null; then
  57. failure "Remove module vboxnetadp:"
  58. return
  59. fi
  60. fi
  61. if ! rmmod vboxdrv 2>/dev/null; then
  62. failure "Remove module vboxdrv:"
  63. return
  64. fi
  65. fi
  66. success
  67. echo
  68. }
  69. restart() {
  70. stop
  71. start
  72. }
  73. status() {
  74. echo -n $"$prog kernel module is "
  75. if running vboxdrv; then
  76. STATUS="loaded"
  77. else
  78. STATUS="not loaded"
  79. fi
  80. echo "$STATUS"
  81. }
  82. case "$1" in
  83. start)
  84. start
  85. ;;
  86. stop)
  87. stop
  88. ;;
  89. restart)
  90. restart
  91. ;;
  92. condrestart)
  93. if [ -f /var/lock/subsys/$PROGNAME ]; then
  94. restart
  95. fi
  96. ;;
  97. status)
  98. status
  99. ;;
  100. *)
  101. INITNAME=`basename $0`
  102. echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  103. exit 1
  104. ;;
  105. esac
  106. exit $RETVAL