○ dropbear 起動スクリプト

*dropbear-0.52を自動起動させるスクリプトです
*完全コピーしないこと(エラーが出ることあり)
*fedoraの起動スクリプトを参考にしています

*"#" で始まる行はコメントとして解釈され、"$" の付いた文字は変数を表します
*スクリプトの先頭で, 処理を行うシェルを明示します (#!/bin/bash)
*# chkconfig: の#のあとに半角スペース
*# description: の#のあとに半角スペース
*. /  . はファイルを読み込むコマンド 後に半角スペース
*[ ] はテストコマンドです 半角スペースを忘れないように
*[ = ] テストコマンド内は = の前後に半角スペース
*環境変数等価式=の場合、前後に半角スペースをいれない
*A && B Aが正ならばBを実効
*A || B Aが為ならばBを実効
*$0 はスクリプト本体 $1は 第1引数
紫色部分 変更追加分

○/etc/rc.d/init.d/dropbear

#!/bin/bash
#
# Init file for dropbear SSH server daemon
#
# chkconfig: 2345 55 25
# description: dropbear SSH server daemon
#
# processname: dropbear
# config: /etc/dropbear/dropbear_dss_host_key
# config: /etc/dropbear/dropbear_rsa_host_key
# pidfile: /var/run/dropbear.pid

# source function library
. /etc/rc.d/init.d/functions

# pull in sysconfig settings
[ -f /etc/sysconfig/dropbear ] && . /etc/sysconfig/dropbear

RETVAL=0
prog="dropbear"

# Some functions to make the below more readable
KEYGEN=/usr/local/bin/dropbearkey
DROPBEAR=/usr/local/sbin/dropbear
RSA_KEY=/etc/dropbear/dropbear_rsa_host_key
DSS_KEY=/etc/dropbear/dropbear_dss_host_key
PID_FILE=/var/run/dropbear.pid

runlevel=$(set -- $(runlevel); eval "echo \$$#" )

do_rsa_keygen() {
    if [ ! -s $RSA_KEY ]; then
        echo -n $"Generating dropbear RSA host key: "
        if $KEYGEN -t rsa -f $RSA_KEY >&/dev/null; then
            chmod 600 $RSA_KEY
            success $"RSA key generation"
            echo
        else
            failure $"RSA key generation"
            echo
            exit 1
        fi
    fi
}

do_dss_keygen() {
    if [ ! -s $DSS_KEY ]; then
        echo -n $"Generating dropbear DSS host key: "
        if $KEYGEN -t dss -f $DSS_KEY >&/dev/null; then
            chmod 600 $DSS_KEY
            success $"DSS key generation"
            echo
        else
            failure $"DSS key generation"
            echo
            exit 1
        fi
    fi
}

start()
{
    # Create keys if necessary
    if [ "x${AUTOCREATE_SERVER_KEYS}" != xNO ]; then
        do_rsa_keygen
        do_dss_keygen
    fi

    echo -n $"Starting $prog: "
    $DROPBEAR $OPTIONS && success || failure
    RETVAL=$?
    [ "$RETVAL" = 0 ] && touch /var/lock/subsys/dropbear
    echo
}

stop()
{
    echo -n $"Stopping $prog: "
    if [ -n "`pidfileofproc $DROPBEAR`" ] ; then
        killproc $DROPBEAR
    else
        failure $"Stopping $prog"
    fi
    RETVAL=$?
    # if we are in halt or reboot runlevel kill all running sessions
    # so the TCP connections are closed cleanly
    if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
        killall $prog 2>/dev/null
    fi
    [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/dropbear
    echo
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    condrestart)
        if [ -f /var/lock/subsys/dropbear ] ; then
            stop
            # avoid race
            sleep 3
            start
        fi
        ;;
    status)
        status $DROPBEAR
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac
exit $RETVAL

dropbear

○ Copyright(c) 528p.com All Rights Reserved.