如何在CentOS 5.10上为已安装的STUNNEL创建服务

银光

我已经在我的centos机器中安装了stunnel,如下所示:

yum install stunnel -y

openssl genrsa -out privkey.pem 2048
openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
cat privkey.pem cacert.pem >> /etc/stunnel/stunnel.pem
chmod 600 /etc/stunnel/stunnel.pem
chown nobody.nobody /var/run/stunnel

nano -K /etc/stunnel/stunnel.conf

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


我的问题是在安装通道之后,没有 针对已安装通道的服务
所以我写了这个:


nano -K /etc/init.d/stunnel

#!/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 ] && touch /var/lock/subsys/stunnel
    echo
    fi
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    killproc /usr/sbin/stunnel
    RETVAL=$?
    [ $RETVAL -eq 0 ] && 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

chmod +x /etc/init.d/stunnel

chkconfig --add stunnel


书面服务的启动命令运行正常:服务通道启动确定

但是我在stop命令期间出错:service stunnel stopFAILED

并且我在状态命令期间出错:服务通道状态
/ sbin / service:66行:7456分段错误env -i LANG =“ $ LANG” PATH =“ $ PATH” TERM =“ $ TERM”“ $ {SERVICEDIR} / $ {SERVICE}“ $ {OPTIONS}

我做错了什么以及如何解决该问题?
有没有更好的方法来获得该服务?

提前致谢

银光

这是您需要的:

#!/bin/bash
#
# Script to run stunnel in daemon mode at boot time.
#
# Check http://www.gaztronics.net/ for the
# most up-to-date version of this script.
#
# This script is realeased under the terms of the GPL.
# You can source a copy at:
# http://www.fsf.org/copyleft/copyleft.html
#
# Please feel free to modify the script to suite your own needs.
# I always welcome email feedback with suggestions for improvements.
# Please do not email for general support. I do not have time to answer
# personal help requests.

# Author: Gary Myers MIIE MBCS
# email: http://www.gaztronics.net/webform/
# Revision 1.0 - 4th March 2005

#====================================================================
# Run level information:
#
# chkconfig: 2345 99 99
# description: Secure Tunnel
# processname: stunnel
#
# Run "/sbin/chkconfig --add stunnel" to add the Run levels.
# This will setup the symlinks and set the process to run at boot.
#====================================================================

#====================================================================
# Paths and variables and system checks.

# Source function library (It's a Red Hat thing!)
. /etc/rc.d/init.d/functions

# Check that networking is up.
#
[ ${NETWORKING} ="yes" ] || exit 0

# Path to the executable.
#
SEXE=`which stunnel`

# Path to the configuration file.
#
CONF=/etc/stunnel/stunnel.conf

# Check the configuration file exists.
#
if [ ! -f $CONF ] ; then
  echo "The configuration file cannot be found!"
exit 0
fi

CHROOT=`grep '^chroot' /etc/stunnel/stunnel.conf | head -n 1 | sed 's/ //g' | awk -F= '{ print $2 }'`
PIDFILE=`grep '^pid' /etc/stunnel/stunnel.conf | head -n 1 | sed 's/ //g' | awk -F= '{ print $2 }'`
if [ -n "$CHROOT" ]; then
    PIDFILE=$CHROOT/$PIDFILE
fi

# Path to the lock file.
#
LOCK_FILE=/var/lock/subsys/stunnel

#====================================================================

#====================================================================
# Run controls:

prog=$"stunnel"

RETVAL=0

# Start stunnel as daemon.
#
start() {
  if [ -f $LOCK_FILE ]; then
    echo "stunnel is already running!"
    exit 0
  else
    echo -n $"Starting $prog: "
    $SEXE $CONF
  fi

  RETVAL=$?
  [ $RETVAL -eq 0 ] && success
  echo
  [ $RETVAL -eq 0 ] && touch $LOCK_FILE
  return $RETVAL
}


# Stop stunnel.
#
stop() {
  if [ ! -f $LOCK_FILE ]; then
    echo "stunnel is not running!"
    exit 0

  else

    echo -n $"Shutting down $prog: "
    killproc -p $PIDFILE stunnel
    RETVAL=$?
    [ $RETVAL -eq 0 ]
     rm -f $LOCK_FILE
    echo
    return $RETVAL

  fi
}

# See how we were called.
case "$1" in
   start)
  start
  ;;
   stop)
  stop
  ;;
   restart)
  stop
  start
  ;;
   condrestart)
  if [ -f $LOCK_FILE ]; then
     stop
     start
     RETVAL=$?
  fi
  ;;
   status)
  status -p $PIDFILE stunnel
  RETVAL=$?
  ;;
   *)
    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
    RETVAL=1
esac

exit $RETVAL

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在CentOS 6.4上安装Red5和Java

来自分类Dev

如何在CentOS 5.x上安装g ++ 4.7.2和c ++ 11?

来自分类Dev

如何检查CentOS 5.x系统上的/ tmp目录是否已安装在tmpfs上?

来自分类Dev

如何在CentOS 5上安装glibc的最新版本,而又不干扰任何现有软件?

来自分类Dev

在centos 5上安装Tensorflow

来自分类Dev

在CentOs 5上安装RubyGem

来自分类Dev

如何在Centos 6.5上安装MonetDB?

来自分类Dev

如何在CentOS上安装PySide?

来自分类Dev

如何在Centos 6上安装jpegrescan?

来自分类Dev

如何在Centos上安装OctoberCMS?

来自分类Dev

如何在CentOS 7上安装Docker?

来自分类Dev

如何在Centos上安装最新的ffmpeg

来自分类Dev

如何在CentOS 6.5上安装libsnmp?

来自分类Dev

如何在centos 6.8上安装spacewalk?

来自分类Dev

如何在CentOS上安装pip?

来自分类Dev

如何在CentOS上安装扑克评估

来自分类Dev

如何在CentOS上安装Docker?

来自分类Dev

如何在CentOS 8上安装jsoncpp

来自分类Dev

如何在 CentOS 8 上安装 beesu?

来自分类Dev

如何在 Centos 6 上安装 Privoxy

来自分类Dev

如何在 Centos 上安装 certutil?

来自分类Dev

如何检查这些php模块(如mod_php5.c)是否已安装在我的服务器上?

来自分类Dev

CentOS 5安装方法

来自分类Dev

如何在服务器上安装ASP.NET MVC 5?

来自分类Dev

如何在Ubuntu 16.04上安装Canon MP459(libtiff4依赖项但已安装libtiff5)

来自分类Dev

如何在CentOS中安装sendmail?

来自分类Dev

如何在CentOS 8下安装phpseclib?

来自分类Dev

如何在centos中安装resolvconf

来自分类Dev

如何在CentOS中创建SFTP用户?