Chinaunix首页 | 论坛 | 博客
  • 博客访问: 516927
  • 博文数量: 135
  • 博客积分: 3568
  • 博客等级: 中校
  • 技术积分: 1942
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-19 17:52
文章分类

全部博文(135)

文章存档

2012年(29)

2011年(41)

2010年(26)

2009年(12)

2008年(9)

2007年(12)

2006年(6)

分类: LINUX

2007-05-19 10:57:27


80服务器因为重新装过系统, 在装ftp服务器的时候由于考虑到FTP服务器需要强大的配置功能, 所以就选择了proftp 而非 vsftp.

资源参考:
官网文档:


http://blog.guomin.net/2006/08/09/158/
proftp 官网:
proftp 主要特色:
一个单一的和 Apache 的 httpd.conf 类似的配置文件
每个目录下的 .ftpaccess 文件(和 Apache 的. htaccess 类似)
很容易配置的,多个虚拟 FTP 服务器以及匿名 FTP 服务
可以单独运行也可以从 inetd/xinetd 启动
匿名 FTP 的根目录不需要特别的目录结构
系统的二进制文件和其他系统文件没有 SITE EXEC 命令
在单独运行方式下,以非特权用户运行,降低攻击风险
日志以及 utmp/wtmp 支持
Shadow 口令支持

安装:
由于考虑到需要 mysql 对虚拟用户的支持, 而 proftp 源码安装才支持此功能, 所以先卸载 已RPM安装的 proftp, vsftp, mysql, 用源码安装 mysql, proftp;
01> 安装 mysql
  安装 mysql-5.0.37-linux-i686-glibc23.tar.gz,
  虽然是二进制安装的,拷贝到你要安装的目录下, 我这里是 /usr/local/mysql 目录下的
  由于未知原因, 发现 /etc/rc.d/init.d 下面有个 mysql的启动脚本,因此只要对它的前两行改吧改吧
  就很容易的用 chkconfig 添加到 service 命令的列表里,毕竟用service比较方便
  启动脚本内容后面给出;
02> 安装 proftp
  安装 proftpd-1.3.1rc2.tar.gz
  # ./configure --prefix=/etc/proftpd --with-modules=mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql --with-includes=/usr/local/mysql/include --with-libraries=/usr/local/mysql/lib
  # /etc/proftpd/sbin/proftpd
  测试

设计:
安装好后是对整个FTP服务目录结构及权限的设计, 我的设计如下:
目录/权限\组      admin tch stdun   ustd   gstd soser
chroot              Y        N    Y       Y        Y       Y
~           rw      YY      YY  YY     YY      YY     YN
/            rw      YY      YN  NN     NN      NN     YN
/pn        rw      YY      YN   --       --        --       NN
/temp    rw      YY      YN   --       --        --       YY
/cb        rw      YY      YN   --       --        --       YN
/un       rw       YY      YN  YY      --        --      YN
其中 ~ 代表每个用户的主目录, 根目录为 用户 hit 的主目录 /home/hit, /pn 代表 /home/hit/personal
/cb 代表 /home/hit/club, /un 代表 "/home/hit/Student Union",  -- 表示未设定, 因为根本访问不到
这里的所有的用户都是虚拟用户, 并且要对 tch, ustd, gstd 组的用户进行配额限制, 防止不良使用FTP服务.

创建本地群组:
//以下的用户是为了让proftp以用户nobody而非root来运行的, 若已经建立了此用户, 跳过
#groupadd -g 99 nobody
#useradd -g nobody nobody
//以下是为了对虚拟用户管理而创建的群组
#groupadd -g 1000 admin
#groupadd -g 1001 soser
#groupadd -g 1002 tch
#groupadd -g 1003 ustd
#groupadd -g 1004 gstd
#groupadd -g 1005 stdun

SQL脚本:
--  >>>>>>>>>> proftpd.sql >>>>>>>>>>>>
/*
ftpgroup:
  sos 相当于一个有公共密码的匿名用户组, 可以下载, 不能看 personal 目录下学生目录里的内容
        但是可以向 temp , recommend 目录中写入
  gstd 研究生组, 主目录本人目录, 执行 chroot
  ustd  本科生组, 主目录本人目录, 执行 chroot
  tch   教室组, 主目录本人目录, 但不执行 chroot, 只能在自己的主目录里可写
  admin FTP管理员组, 拥有所有权限
*/

CREATE DATABASE IF NOT EXISTS proftpd;
USE proftpd;
DROP TABLE IF EXISTS `ftpgroup`;
CREATE TABLE `ftpgroup` (
`groupname`    VARCHAR(64)   NOT NULL,
`gid`          SMALLINT      NOT NULL,
  `members`      VARCHAR(64),
PRIMARY KEY (`groupname`, `gid`)
--`gid`          SMALLINT      NOT NULL  AUTO_INCREMENT key,
--组的成员, 用逗号隔开
);-- TYPE=MyISAM COMMENT='ProFTP group table';
--ALTER TABLE `ftpgroup` AUTO_INCREMENT=100;
INSERT INTO `ftpgroup`(`groupname`, `gid`, `members`) VALUES ('nobody',     99, 'nobody');       /* 100 */
INSERT INTO `ftpgroup`(`groupname`, `gid`, `members`) VALUES ('admin',     1000, '');       /* 100 */
INSERT INTO `ftpgroup`(`groupname`, `gid`, `members`) VALUES ('soser',       1001, '');       /* 101 */
INSERT INTO `ftpgroup`(`groupname`, `gid`, `members`) VALUES ('tch',           1002, '');          /* 102 */
INSERT INTO `ftpgroup`(`groupname`, `gid`, `members`) VALUES ('ustd',         1003,  '');         /* 103 */
INSERT INTO `ftpgroup`(`groupname`, `gid`, `members`) VALUES ('gstd',          1004, '');         /* 104 */
INSERT INTO `ftpgroup`(`groupname`, `gid`, `members`) VALUES ('stdun',       1005, '');      /* 105 */

--注意: 可以使用符号  来引用表名, 列名
DROP TABLE IF EXISTS `ftpuser`;
CREATE TABLE `ftpuser` (
`userid`       VARCHAR(64)    NOT NULL,
`passwd`       VARCHAR(64)    NOT NULL,
--用户id
`uid`          INT     NOT NULL AUTO_INCREMENT KEY,
`gid`          INT     NOT NULL,
--用户主目录
`homedir`      VARCHAR(255),
--用户的系统Shell
`shell`        VARCHAR(64) DEFAULT '/sbin/nologin',
`count`        INT     NOT NULL  DEFAULT 0,
`accessed`     DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified`     DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
);
ALTER TABLE `ftpuser` AUTO_INCREMENT=1000;
INSERT INTO `ftpuser` (`userid`, `passwd`, `gid`, `homedir`)
VALUES ('adm', password('adm'), '1000', '/home/hit/');
INSERT INTO `ftpuser` (`userid`, `passwd`, `gid`, `homedir`)
VALUES ('sos', password('sos'), '1001', '/home/hit/');
-- 用户 hit 虽然和系统本地用户同名, 但是可以更改验证顺序通过,
-- 是为了老用户的习惯而设定
INSERT into `ftpuser`(`userid`, `passwd`, `gid`, `homedir`)
VALUES('hit',password('software'),'1001','/home/hit/');
INSERT INTO `ftpuser` (`userid`, `passwd`, `gid`, `homedir`)
VALUES ('dudu', password('dudu'), '1002', '/home/hit/personal/teacher/dudu');
INSERT INTO `ftpuser` (`userid`, `passwd`, `gid`, `homedir`)
VALUES ('041110108', password('041110108'), '1003', '/home/hit/personal/undergraduate student/041110108');
INSERT INTO `ftpuser` (`userid`, `passwd`, `gid`, `homedir`)
VALUES ('041110109', password('041110109'), '1004', '/home/hit/personal/graduate student/041110109');
INSERT INTO `ftpuser` (`userid`, `passwd`, `gid`, `homedir`)
VALUES ('yu', password('yu'), '1005', '/home/hit/Student Union');

--建立磁盘限额数据表
DROP TABLE IF EXISTS `quotalimits`;
CREATE TABLE `quotalimits` (
--由程序自动记录
`name`             VARCHAR(64) NOT NULL,
--磁盘限额类别
`quota_type`       ENUM('user','group','class','all') NOT NULL DEFAULT 'user',
`per_session`      ENUM('false','true') NOT NULL DEFAULT 'false',
`limit_type`       ENUM('soft','hard')  NOT NULL DEFAULT 'soft',
--上传最大字节数, 就是FTP用户空间容量
`bytes_in_avail`   FLOAT NOT NULL DEFAULT '0',
--下载最大字节数
`bytes_out_avail`  FLOAT NOT NULL DEFAULT '0',
--总共可传输的文件的最大字节数(速率)(上传和下载流量)
`bytes_xfer_avail` FLOAT NOT NULL DEFAULT '0',
--总共能上传的文件数
`files_in_avail`   INT UNSIGNED NOT NULL DEFAULT '0',
--总共能从服务器下载文件的数目
`files_out_avail`  INT UNSIGNED NOT NULL DEFAULT '0',
--总共可传输文件的数目(上传和下载)
`files_xfer_avail` INT UNSIGNED NOT NULL DEFAULT '0'
);
INSERT INTO quotalimits (name, quota_type, per_session, limit_type,
bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail)
VALUES ('041110108', 'user', 'false', 'soft', '1048576', '0','0','0','0','0');
INSERT INTO quotalimits (name, quota_type, per_session, limit_type,
bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail)
VALUES ('041110109', 'user', 'false', 'soft', '104857600', '0','0','0','0','0');
INSERT INTO quotalimits (name, quota_type, per_session, limit_type,
bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail)
VALUES ('dudu', 'user', 'false', 'soft', '314572800', '0','0','0','0','0');

DROP TABLE IF EXISTS `quotatallies`;
CREATE TABLE `quotatallies` (
`name`             VARCHAR(64) NOT NULL,
`quota_type`       ENUM('user','group','class','all') NOT NULL DEFAULT 'user',
`bytes_in_used`    FLOAT NOT NULL DEFAULT '0',
`bytes_out_used`   FLOAT NOT NULL DEFAULT '0',
`bytes_xfer_used`  FLOAT NOT NULL DEFAULT '0',
`files_in_used`    INT UNSIGNED NOT NULL DEFAULT '0',
`files_out_used`   INT UNSIGNED NOT NULL DEFAULT '0',
`files_xfer_used`  INT UNSIGNED NOT NULL DEFAULT '0');
GRANT ALL ON proftpd.* TO [email=proftpd@localhost]proftpd@localhost[/email] identified by 'proftpd';


配置:
让我们来使用配置文件 /etc/proftpd/etc/proftpd.conf 来介绍 proftp 的配置文件语法:
对于 "/home/hit/Student Union", /home/hit/club 目录的配置省略.
######################### /etc/proftpd/etc/proftpd.conf ###################################
ServerName   "FTP of SoS"    #FTP服务显示给客户端的服务名称
ServerType   standalone      #独立运行的方式, 而不是 inetd 子进程的方式运行
DefaultServer   on
Port    21              #FTP 端口, 标准端口 - 21
Umask    000             #FTP读写文件所用的 umask 值,
MaxInstances   60          #同时可有多少线程,
User    nobody          #FTP将以哪个用户来运行
Group    nobody          #FTP将以那个组来运行
                  #禁止所有用户执行 chmod 命令
  DenyAll

#________________虚拟用户组列表  ________________________
# 以下都是组名, 存在于本地系统, 需要先用 groupadd 命令创建

  AllowGroup   admin    #允许管理员组的所有用户登陆, 以下类似
  AllowGroup   soser
  AllowGroup   tch
  AllowGroup   gstd
  AllowGroup   ustd
  AllowGroup   stdun
  AllowGroup  web80
  DenyAll               #其他组的用户禁止登陆

# 注释掉所有的 标签可以禁止 匿名用户登陆
#_________________匿名用户设置_________________________
#       #匿名用户名为 dd 的配置, 登陆目录为 ~ (主目录) 默认为 /var/ftp/pub
#

#  #匿名用户名为 ftp 的主目录为 /home/hit
#  User    ftp             #匿名用户名, 不存在于本地系统, 可以有多个
#  Group   ftp             #该匿名用户所属的组, 组由 groupadd 添加
#  AnonRequirePassword  on      #是否需要输入密码
#                      #对 命令 login 的限制, 为 允许所有
#    AllowAll
#  

# 匿名用户别名, 以下设置可以使 客户端使用 "ftp" 而不是 "anonymous" 来登陆
#  UserAlias   anonymous ftp
  # 同时可以有多少匿名用户同时登陆
#  MaxClients   10 "Sorry, max %m users -- try again later!"
#  DisplayLogin   welcome.msg     #  设置欢迎信息
#  DisplayChdir   .message
#                          #禁止匿名用户写权限
#    DenyAll
#  

#

#___________________基本设置_________________________
TimeoutStalled   300             #下载延时大于 300 时断开连接
DisplayLogin   welcome.msg     #登陆欢迎信息
DisplayChdir   .message        #更换目录欢迎信息
DirFakeUser       on sos          #客户端 ls -l 时所看到的文件属主
DirFakeGroup   on sos          #客户端 ls -l 时所看到的文件属组
DirFakeMode       0000            #客户端 ls -l 时所看到的文件权限
# PAM(plugable authentication module ,可插拔认证模块), on 启用
# 因为需要用到 基于数据库的 虚拟用户, 所以要用到.
AuthPAM    on

#@@@@@@@@@@@@@@  目录访问权限控制  @@@@@@@@@@@@@@@@@@@@@
#如果虚拟用户存在而它的登陆目录不存在, 则该用户登陆时自动以给定的权限创
#建主目录 和 主目录不存在的父级目录
CreateHome   on 777 dirmode 777
# 是否允许覆盖已有文件
AllowOverwrite  on

#对每个用户的主目录 ~ 的权限设定
#对命令 write 的限制设定
  AllowAll


# HideFiles 必须写在 Directory  标签里
# 对目录 /home/hit 的总体设置, 该目录是所有FTP用户的根目录
# 隐藏以 . 开头的(即隐藏)文件和用户 hit 的桌面目录 Destop
    HideFiles  ^(\..*|Desktop)$
# 隐藏不能够访问的文件
HideNoAccess  on
#禁止 soser 和 tch 组的用户在该目录的写权限
  DenyGroup  soser
  DenyGroup  tch



# 设置临时文件目录的权限设置
#只有 组 admin 和 soser 的用户可以有写权限
  DenyAll
  AllowGroup  admin
  AllowGroup  soser



# 防止通过匿名用户拷贝其他同学的作业
  DenyGroup  soser




  DenyGroup  soser



#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# 只有 tch 组的用户登陆后不执行不执行 chroot 命令, 而其他组都限制在自己的主目录中
DefaultRoot  ~ !tch
# 但是 tch 组的用户也必须设置一个新的根目录, 而不是操作系统的根目录 / .
DefaultRoot  /home/hit tch

IdentLookups   on
UseReverseDNS   on
# emerg, alert, crit (empfohlen), error, warn. notice, info, debug
SyslogLevel   emerg   #日志记录级别
#日志记录文件
SystemLog   /var/log/proftpd/emerg.log
#日志各种命令的记录格式
TransferLog   /var/log/vsftpd/xfer.log
LogFormat            default "%h %l %u %t \"%r\" %s %b"
LogFormat            auth    "%v [%P] %h %t \"%r\" %s"
LogFormat            write   "%h %l %u %t \"%r\" %s %b"
# Log file/dir access
ExtendedLog           /var/log/proftpd/access.log    WRITE,READ write
# Record all logins
ExtendedLog            /var/log/proftpd/auth.log      AUTH auth
# Paranoia logging level....
ExtendedLog            /var/log/proftpd/paranoid.log  ALL default

################ MySql Info ####################################################
##  groups 和 users 不能同时认证
SQLAuthTypes   Backend Plaintext  #先用 mysql 的password()来验证密码, 再用普通文本验证密码
SQLAuthenticate   users usersetfast
# mysql 数据库的连接字符串, 第一个 proftpd 是表名, 第二个是用户名, 第三个是密码
SQLConnectInfo   [email=proftpd@localhost]proftpd@localhost[/email] proftpd proftpd
# 数据库中记录用户信息的表名及相关信息的字段名
# ftpuser 是表名, 其后依次是必须的相关字段名,
# 格式为: SQLUserInfo [ user-table user-name passwd uid gid home-dir shell]
SQLUserInfo   ftpuser userid passwd uid gid homedir shell
#貌似以 user 或 group 进行登陆验证中的一种均可, 所以以下的被注释掉了, ??? 望纠正
#SQLGroupInfo  ftpgroup groupname gid members
#SQLDefaultGID   65534   #
#SQLDefaultGID   63333
#SQLDefaultUID   63333
#SQLMinUserGID    100
#SQLMinUserUID                  500
#SQL日志文件, 指明文件就记录, 不指明就不记录, 可以帮助调错, 比如proftpd.conf 中的
#sql 语句有误等都可以通过该日志得知, 但是是建议关闭
#SQLLogFile   /var/log/proftpd/sqlLog.log
#对用户登陆验证命令 PASS 执行的 SQL语句, 可以将日志记录到数据库中
# 对 命令PASS 执行名称为 "counter" 的SQL query, 它在随后有定义
SQLLog    PASS counter
#名称为 "counter" 的SQL Qurey 的定义类型为 UPDATE, 语句为其后的字符串, 表名为 ftpuser
# 相关的转义字符 %u 等可以在 官网差 LogFormat , SQLNamedQuery 中找到
SQLNamedQuery   counter UPDATE "count=count+1,accessed=now()   \
  WHERE userid='%u'" ftpuser
# xfer log in mysql
SQLLog    STOR,DELE transfer1
SQLNamedQuery   transfer1 UPDATE "modified=now() where         \
  userid='%u'" ftpuser


################ Quota Info ####################################################

#
#
QuotaDirectoryTally on
QuotaDisplayUnits "Kb"
QuotaEngine  on
QuotaLock  /etc/proftpd/quota.lock
QuotaLog  "/var/log/proftpd/quota.log"
#允许显示磁盘限额信息,ftp登录后可执行"quote", "site quota"命令查看当前磁盘使用情况
QuotaShowQuotas  on
#指定磁盘限额模块使用的数据库信息
#定义几个相关的 SQL Query
SQLNamedQuery  get-quota-limit  SELECT "name, quota_type,   \
per_session, limit_type, bytes_in_avail, bytes_out_avail, bytes_xfer_avail, \
files_in_avail, files_out_avail, files_xfer_avail FROM quotalimits WHERE    \
name='%{0}' AND quota_type='%{1}'"
SQLNamedQuery   get-quota-tally  SELECT "name, quota_type,   \
bytes_in_used, bytes_out_used, bytes_xfer_used, files_in_used,              \
files_out_used, files_xfer_used FROM quotatallies WHERE name='%{0}' AND     \
quota_type='%{1}'"
SQLNamedQuery   update-quota-tally UPDATE "bytes_in_used =     \
bytes_in_used+%{0}, bytes_out_used=bytes_out_used+%{1}, bytes_xfer_used =   \
bytes_xfer_used+%{2}, files_in_used=files_in_used+%{3}, files_out_used =    \
files_out_used+%{4}, files_xfer_used=files_xfer_used+%{5} WHERE name='%{6}' \
AND quota_type='%{7}'" quotatallies
SQLNamedQuery  insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3},  \
%{4}, %{5}, %{6}, %{7}" quotatallies
# 为以下两个标签分配相关的 SQL Query 命令
QuotaLimitTable  sql:/get-quota-limit
QuotaTallyTable  sql:/get-quota-tally/update-quota-tally/insert-quota-tally
#

#

################################################################################

让 proftpd 支持 FXP:
在proftpd.conf 里加入如下配置:
    AllowForeignAddress on   #开启FXP功能
    PassivePorts        60000 65534  #打开Passive模式且端口范围为 60000~65534
然后在 /etc/sysconfig/iptables 加入如下语句以打开防火墙的端口60000~65534
    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 60000:65534 -j ACCEPT

service 脚本
################### /etc/init.d/mysql #################
#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind
# MySQL daemon start/stop script.
# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.
# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO

# If you install MySQL on some other places than /, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
# The following variables are only set for letting mysql.server find things.
# Set some defaults
pid_file=
server_pid_file=
use_mysqld_safe=1
user=mysql
if test -z "$basedir"
then
  basedir=/
  bindir=/usr/bin
  if test -z "$datadir"
  then
    datadir=/var/lib/mysql
  fi
  sbindir=/usr/sbin
  libexecdir=/usr/sbin
else
  bindir="$basedir/bin"
  if test -z "$datadir"
  then
    datadir="$basedir/data"
  fi
  sbindir="$basedir/sbin"
  libexecdir="$basedir/libexec"
fi
# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=
#
# Use LSB init script functions for printing messages, if possible
#
lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then
  . $lsb_functions
else
  log_success_msg()
  {
    echo " SUCCESS! $@"
  }
  log_failure_msg()
  {
    echo " ERROR! $@"
  }
fi
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
export PATH
mode=$1    # start or stop
shift
other_args="$*"   # uncommon, but needed when called from an RPM upgrade action
           # Expected: "--skip-networking --skip-grant-tables"
           # They are not checked here, intentionally, as it is the resposibility
           # of the "spec" file author to give correct arguments only.
case `echo "testing\c"`,`echo -n testing` in
    *c*,-n*) echo_n=   echo_c=     ;;
    *c*,*)   echo_n=-n echo_c=     ;;
    *)       echo_n=   echo_c='\c' ;;
esac
parse_server_arguments() {
  for arg do
    case "$arg" in
      --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
                    bindir="$basedir/bin"
      if test -z "$datadir_set"; then
        datadir="$basedir/data"
      fi
      sbindir="$basedir/sbin"
      libexecdir="$basedir/libexec"
        ;;
      --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
      datadir_set=1
;;
      --user=*)  user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --pid-file=*) server_pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --use-mysqld_safe) use_mysqld_safe=1;;
      --use-manager)     use_mysqld_safe=0;;
    esac
  done
}
parse_manager_arguments() {
  for arg do
    case "$arg" in
      --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --user=*)  user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
    esac
  done
}
wait_for_pid () {
  i=0
  while test $i -lt 900 ; do
    sleep 1
    case "$1" in
      'created')
        test -s $pid_file && i='' && break
        kill -0 $2 || break # if the program goes away, stop waiting
        ;;
      'removed')
        test ! -s $pid_file && i='' && break
        ;;
      *)
        echo "wait_for_pid () usage: wait_for_pid created|removed"
        exit 1
        ;;
    esac
    echo $echo_n ".$echo_c"
    i=`expr $i + 1`
  done
  if test -z "$i" ; then
    log_success_msg
    return 0
  else
    log_failure_msg
    return 1
  fi
}
# Get arguments from the my.cnf file,
# the only group, which is read from now on is [mysqld]
if test -x ./bin/my_print_defaults
then
  print_defaults="./bin/my_print_defaults"
elif test -x $bindir/my_print_defaults
then
  print_defaults="$bindir/my_print_defaults"
elif test -x $bindir/mysql_print_defaults
then
  print_defaults="$bindir/mysql_print_defaults"
else
  # Try to find basedir in /etc/my.cnf
  conf=/etc/my.cnf
  print_defaults=
  if test -r $conf
  then
    subpat='^[^=]*basedir[^=]*=\(.*\)$'
    dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
    for d in $dirs
    do
      d=`echo $d | sed -e 's/[  ]//g'`
      if test -x "$d/bin/my_print_defaults"
      then
        print_defaults="$d/bin/my_print_defaults"
        break
      fi
      if test -x "$d/bin/mysql_print_defaults"
      then
        print_defaults="$d/bin/mysql_print_defaults"
        break
      fi
    done
  fi
  # Hope it's in the PATH ... but I doubt it
  test -z "$print_defaults" && print_defaults="my_print_defaults"
fi
#
# Read defaults file from 'basedir'.   If there is no defaults file there
# check if it's in the old (depricated) place (datadir) and read it from there
#
extra_args=""
if test -r "$basedir/my.cnf"
then
  extra_args="-e $basedir/my.cnf"
else
  if test -r "$datadir/my.cnf"
  then
    extra_args="-e $datadir/my.cnf"
  fi
fi
parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`
# Look for the pidfile
parse_manager_arguments `$print_defaults $extra_args manager`
#
# Set pid file if not given
#
if test -z "$pid_file"
then
  pid_file=$datadir/mysqlmanager-`/bin/hostname`.pid
else
  case "$pid_file" in
    /* ) ;;
    * )  pid_file="$datadir/$pid_file" ;;
  esac
fi
if test -z "$server_pid_file"
then
  server_pid_file=$datadir/`/bin/hostname`.pid
else
  case "$server_pid_file" in
    /* ) ;;
    * )  server_pid_file="$datadir/$server_pid_file" ;;
  esac
fi
# Safeguard (relative paths, core dumps..)
cd $basedir
case "$mode" in
  'start')
    # Start daemon
    manager=$bindir/mysqlmanager
    if test -x $libexecdir/mysqlmanager
    then
      manager=$libexecdir/mysqlmanager
    elif test -x $sbindir/mysqlmanager
    then
      manager=$sbindir/mysqlmanager
    fi
    echo $echo_n "Starting MySQL"
    if test -x $manager -a "$use_mysqld_safe" = "0"
    then
      if test -n "$other_args"
      then
        log_failure_msg "MySQL manager does not support options '$other_args'"
        exit 1
      fi
      # Give extra arguments to mysqld with the my.cnf file. This script may
      # be overwritten at next upgrade.
      $manager --user=$user --pid-file=$pid_file >/dev/null 2>&1 &
      wait_for_pid created $!; return_value=$?
      # Make lock for RedHat / SuSE
      if test -w /var/lock/subsys
      then
        touch /var/lock/subsys/mysqlmanager
      fi
      exit $return_value
    elif test -x $bindir/mysqld_safe
    then
      # Give extra arguments to mysqld with the my.cnf file. This script
      # may be overwritten at next upgrade.
      pid_file=$server_pid_file
      $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
      wait_for_pid created $!; return_value=$?
      # Make lock for RedHat / SuSE
      if test -w /var/lock/subsys
      then
        touch /var/lock/subsys/mysql
      fi
      exit $return_value
    else
      log_failure_msg "Couldn't find MySQL manager or server"
    fi
    ;;
  'stop')
    # Stop daemon. We use a signal here to avoid having to know the
    # root password.
    # The RedHat / SuSE lock directory to remove
    lock_dir=/var/lock/subsys/mysqlmanager
    # If the manager pid_file doesn't exist, try the server's
    if test ! -s "$pid_file"
    then
      pid_file=$server_pid_file
      lock_dir=/var/lock/subsys/mysql
    fi
    if test -s "$pid_file"
    then
      mysqlmanager_pid=`cat $pid_file`
      echo $echo_n "Shutting down MySQL"
      kill $mysqlmanager_pid
      # mysqlmanager should remove the pid_file when it exits, so wait for it.
      wait_for_pid removed; return_value=$?
      # delete lock for RedHat / SuSE
      if test -f $lock_dir
      then
        rm -f $lock_dir
      fi
      exit $return_value
    else
      log_failure_msg "MySQL manager or server PID file could not be found!"
    fi
    ;;
  'restart')
    # Stop the service and regardless of whether it was
    # running or not, start it again.
    if $0 stop  $other_args; then
      $0 start $other_args
    else
      log_failure_msg "Failed to stop running server, so refusing to try to start."
      exit 1
    fi
    ;;
  'reload')
    if test -s "$server_pid_file" ; then
      mysqld_pid=`cat $server_pid_file`
      kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"
      touch $server_pid_file
    else
      log_failure_msg "MySQL PID file could not be found!"
    fi
    ;;
  *)
    # usage
    echo "Usage: $0  {start|stop|restart|reload}  [ MySQL server options ]"
    exit 1
    ;;
esac
exit 0

###################### /etc/init.d/proftpd #####################
#!/bin/sh
# $Id: proftpd.init,v 1.1 2004/02/26 17:54:30 thias Exp $
#
# proftpd This shell script takes care of starting and stopping
#  proftpd.
#
# chkconfig: - 80 30
# description: ProFTPD is an enhanced FTP server with a focus towards \
#              simplicity, security, and ease of configuration. \
#              It features a very Apache-like configuration syntax, \
#              and a highly customizable server infrastructure, \
#              including support for multiple 'virtual' FTP servers, \
#              anonymous FTP, and permission-based directory visibility.
# processname: proftpd
# config: /etc/proftp.conf
# pidfile: /var/run/proftpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# modified by btpka3
#[ -x /usr/sbin/proftpd ] || exit 0 >/dev/null
[ -x /etc/proftpd/sbin/proftpd ] || exit 0
RETVAL=0
prog="proftpd"
start() {
echo -n $"Starting $prog: "
daemon /etc/proftpd/sbin/proftpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/proftpd
}
stop() {
echo -n $"Shutting down $prog: "
killproc /etc/proftpd/sbin/proftpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/proftpd
}
# See how we were called.
case "$1" in
  start)
start
;;
  stop)
stop
;;
  status)
status proftpd
RETVAL=$?
;;
  restart)
stop
start
;;
  condrestart)
if [ -f /var/lock/subsys/proftpd ]; then
   stop
   start
fi
;;
  reload)
echo -n $"Re-reading $prog configuration: "
killproc proftpd -HUP
RETVAL=$?
echo
;;
  *)
echo "Usage: $prog {start|stop|restart|reload|condrestart|status}"
exit 1
esac
exit $RETVAL
阅读(3071) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~