title: how create a service for installed STUNNEL on CentOS 5.10
body: <p>i have installed stunnel in my centos machine like below :  </p>
  
  <p><code>yum install stunnel -y</code></p>
  
  <pre><code>openssl genrsa -out privkey.pem 2048
  openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
  cat privkey.pem cacert.pem &gt;&gt; /etc/stunnel/stunnel.pem
  chmod 600 /etc/stunnel/stunnel.pem
  chown nobody.nobody /var/run/stunnel
  </code></pre>
  
  <p><code>nano -K /etc/stunnel/stunnel.conf</code></p>
  
  <pre><code>cert = /etc/stunnel/stunnel.pem
  chroot = /var/run/stunnel/
  pid = /stunnel.pid
  setuid = nobody
  setgid = nobody
  output = stunnel.log
  
  [squid]
  # Ensure the ‘connect’ line matches your squid port. Default is 3128
  accept = 8088
  connect = 127.0.0.1:1945
  </code></pre>
  
  <p><HR></p>
  
  <p>my problem is after stunnel installation <strong>there is no</strong> <strong>service</strong> for installed stunnel.<br>
  so i wrote this :   </p>
  
  <p><HR></p>
  
  <p><code>nano -K /etc/init.d/stunnel</code></p>
  
  <pre><code>#!/bin/bash
  #       /etc/rc.d/init.d/stunnel
  #
  # Starts the stunnel daemon
  #
  # chkconfig: 345 70 30
  # description: Stunnel Server is a ...
  # processname: stunnel
  # config: /etc/stunnel/stunnel.conf
  
  # Source function library.
  . /etc/init.d/functions
  
  test -x /usr/sbin/stunnel || exit 0
  RETVAL=0
  #
  #       See how we were called.
  #
  prog="stunnel"
  start() {
      # Check if stunnel is already running
      if [ ! -f /var/lock/subsys/stunnel ]; 
      then
      echo -n $"Starting $prog: "
      daemon /usr/sbin/stunnel
      RETVAL=$?
      [ $RETVAL -eq 0 ] &amp;&amp; touch /var/lock/subsys/stunnel
      echo
      fi
      return $RETVAL
  }
  stop() {
      echo -n $"Stopping $prog: "
      killproc /usr/sbin/stunnel
      RETVAL=$?
      [ $RETVAL -eq 0 ] &amp;&amp; rm -f /var/lock/subsys/stunnel
      echo
      return $RETVAL
  }
  restart() {
      stop
      start
  }
  reload() {
      restart
  }
  status() {
      status /usr/sbin/stunnel
  }
  case "$1" in
  start)
      start
      ;;
  stop)
      stop
      ;;
  reload|restart)
      restart
      ;;
  status)
      status
      ;;
  *)
      echo $"Usage: $0 {start|stop|restart|reload|status}"
      exit 1
  esac
  exit $?
  exit $RETVAL
  </code></pre>
  
  <p><code>chmod +x /etc/init.d/stunnel</code></p>
  
  <p><code>chkconfig --add stunnel</code></p>
  
  <p><HR></p>
  
  <p>the start command for the written service works fine : <strong>service stunnel start</strong> : <strong>OK</strong>.  </p>
  
  <p>but i have error during stop command : <strong>service stunnel stop</strong>  : <strong>FAILED</strong>  </p>
  
  <p>and i have error during status command : <strong>service stunnel status</strong> :<br>
  <strong>/sbin/service: line 66:  7456 Segmentation fault      env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS}</strong>  </p>
  
  <p>what did i do wrong and how can i fix the problem?<br>
  is there a better way for getting that service?   </p>
  
  <p>thanks in advance</p>