编写启动、停止、重启的脚本

2023-05-19 17:42:17 浏览数 (2)

代码语言:javascript复制
#!/bin/bash    
# ProFTPd Settings 
PROFTPD="/usr/local/proftpd/sbin/proftpd" 
PROCONF="/usr/local/proftpd/etc/proftpd.conf" 
PROPID="/usr/local/proftpd/var/proftpd.pid" 
RETVAL=0 
prog="ProFTPd" 
   
start() { 
    echo -n $"Starting $prog... " 
    $PROFTPD -c $PROCONF 
    if [ "$?" = 0 ] ; then 
        echo " done" 
    else 
        echo " failed" 
    fi 
} 
   
stop() { 
    echo -n $"Stopping $prog...  " 
    if [ ! -e $PROPID ]; then 
        echo -n $"$prog is not running." 
        exit 1 
    fi 
    kill `cat $PROPID` 
    if [ "$?" = 0 ] ; then 
        echo " done" 
    else 
        echo " failed" 
    fi 
} 
   
restart(){ 
    echo $"Restarting $prog..." 
    $0 stop 
    sleep 2 
    $0 start 
} 
   
status(){ 
    if [ -e $PROPID ]; then 
        echo $"$prog is running." 
    else 
        echo $"$prog is not running." 
    fi 
} 
   
case "$1" in 
    start) 
        start 
        ;; 
    stop) 
        stop 
        ;; 
    restart) 
        restart 
        ;; 
    status) 
        status 
        ;; 
  *) 
        echo $"Usage: $0 {start|stop|restart|status}" 
esac 

0 人点赞