stunnel-init 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. #
  3. # Init Script to run stunnel in daemon mode at boot time.
  4. #
  5. # Author: Riccardo Riva - RPM S.r.l.
  6. # Revision 1.0 - 2010 November, 11
  7. #====================================================================
  8. # Run level information:
  9. #
  10. # chkconfig: 2345 99 99
  11. # description: Secure Tunnel
  12. # processname: stunnel
  13. #
  14. # Run "/sbin/chkconfig --add stunnel" to add the Run levels.
  15. # This will setup the symlinks and set the process to run at boot.
  16. #====================================================================
  17. #====================================================================
  18. # Paths and variables and system checks.
  19. # Source function library
  20. . /etc/rc.d/init.d/functions
  21. # Check that networking is up.
  22. #
  23. [ ${NETWORKING} ="yes" ] || exit 0
  24. # Path to the executable.
  25. #
  26. SEXE=/usr/bin/stunnel
  27. # Path to the configuration file.
  28. #
  29. CONF=/etc/stunnel/stunnel.conf
  30. # Check the configuration file exists.
  31. #
  32. if [ ! -f $CONF ] ; then
  33. echo "The configuration file cannot be found!"
  34. exit 0
  35. fi
  36. # Path to the lock file.
  37. #
  38. LOCK_FILE=/var/lock/subsys/stunnel
  39. #====================================================================
  40. # Run controls:
  41. prog=$"stunnel"
  42. RETVAL=0
  43. # Start stunnel as daemon.
  44. #
  45. start() {
  46. if [ -f $LOCK_FILE ]; then
  47. echo "stunnel is already running!"
  48. exit 0
  49. else
  50. echo -n $"Starting $prog: "
  51. $SEXE $CONF
  52. fi
  53. RETVAL=$?
  54. [ $RETVAL -eq 0 ] && success
  55. echo
  56. [ $RETVAL -eq 0 ] && touch $LOCK_FILE
  57. return $RETVAL
  58. }
  59. # Stop stunnel.
  60. #
  61. stop() {
  62. if [ ! -f $LOCK_FILE ]; then
  63. echo "stunnel is not running!"
  64. exit 0
  65. else
  66. echo -n $"Shutting down $prog: "
  67. killproc stunnel
  68. RETVAL=$?
  69. [ $RETVAL -eq 0 ]
  70. rm -f $LOCK_FILE
  71. echo
  72. return $RETVAL
  73. fi
  74. }
  75. # See how we were called.
  76. case "$1" in
  77. start)
  78. start
  79. ;;
  80. stop)
  81. stop
  82. ;;
  83. restart)
  84. stop
  85. start
  86. ;;
  87. condrestart)
  88. if [ -f $LOCK_FILE ]; then
  89. stop
  90. start
  91. RETVAL=$?
  92. fi
  93. ;;
  94. status)
  95. status stunnel
  96. RETVAL=$?
  97. ;;
  98. *)
  99. echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  100. RETVAL=1
  101. esac
  102. exit $RETVAL
  103. #--- End of file ---