[ 戻る ] | [ ホームへ ]

◆ デーモン化と自動起動・停止

 ドミノサーバをデーモン化する方法としては幾つかのアイディアがあると思われます。 まずはGNUのscreenを利用する方法、次に入出力リダイレクションを切替える方法。 全社の場合は「screen -d 」で可能ですが、 日本語との相性が悪そうなので、後者のシンプルな方法によりデーモン化し、 自動起動・停止することを考えます。但しこの場合のデメリットとして、 サーバから直接コマンドを入力できなくなります。 通常は管理者クライアントよりコンソール操作するので不便はないのですが(^^;

1. ドミノの起動方法
ドミノサーバの起動は下記のようなスタイルで行なうことにします。
/opt/lotus/bin/server < input > output
2. ドミノの停止
ドミノサーバは下記のコマンドにより停止します。
/opt/lotus/bin/server -q
3. 起動スクリプト
ドミノサーバの起動用スクリプトファイル「start_server」を、 インストール先(実行ファイルがあるディレクトリ)「/opt/lotus/bin/」に作成します。

/opt/lotus/bin/start_server
#!/bin/sh

NOTES_USER=notes
NOTES_PATH=/local/notesdata
OUTPUT_LOG=/var/log/notes/$NOTES_USER.log
PATH=$PATH:$NOTES_PATH:/opt/lotus/bin

if [ `id -u` = 0 ]
then
echo "Run the Domino Server as the notes user"
exit 1
fi

if [ ! -x /opt/lotus/bin/server ]
then
echo "Notes: Cannot access server command - exiting"
exit 1
fi

if [ ! -d $NOTES_PATH ]
then
echo "Notes: Cannot access notes data directory - exiting"
exit 1
fi

cd $NOTES_PATH

if [ -a $OUTPUT_LOG ]
then
cp -p $OUTPUT_LOG $OUTPUT_LOG.`date +"%m%d%y_%H%M"`
fi

echo "Starting Domino 5 server ... "
/opt/lotus/bin/server < /local/notesdata/.passwd > $OUTPUT_LOG 2>&1 &
4. 停止スクリプト
ドミノサーバの停止用スクリプトファイル「stop_server」を、 インストール先(実行ファイルがあるディレクトリ)「/opt/lotus/bin/」に作成します。

/opt/lotus/bin/stop_server
#!/bin/sh

NOTES_USER=notes
NOTES_PATH=/local/notesdata
OUTPUT_LOG=/var/log/notes/$NOTES_USER.log
INPUT_FILE=$NOTES_PATH/$NOTES_USER.input

echo "Stopping the Domino 5 Server for Linux"
echo " ... waiting for shutdown to complete"

cd $NOTES_PATH
/opt/lotus/bin/server -q > /dev/null 2>&1 &

count=0
NOTES_RUNNING=`ps -ef | grep /opt/lotus/notes | grep -v grep`

while [ -n $NOTES_RUNNING ] ; do
sleep 10
count=`expr $count + 1`
echo " ... waiting "$count"0 seconds"

if [ $count = 13 ]
then
echo "Domino Server is still running after 2 minutes"
echo " ... now for the ungraceful method"
for i in `ps -ef | grep /opt/lotus/notes | grep -v grep | awk '{ print $2 }'`
do
kill -9 $i
done

echo " ... Notes server TERMINATED"
exit 
fi

NOTES_RUNNING=`ps -ef | grep /opt/lotus/notes | grep -v grep`
done

echo "Notes server ended cleanly" 
exit 0 
5. スタートアップスクリプト
スタートアップ・スクリプトファイル「notes」を、 「/etc/rc.d/init.d」に作成します。

/etc/rc.d/init.d/notes
#!/bin/sh
. /etc/rc.d/init.d/functions

case "$1" in
start)
echo -n "Starting Lotus Domino server: "
if [ -d /local/notesdata -a -f /opt/lotus/bin/server ] ; then
su notes -c /opt/lotus/bin/start_server
fi 
touch /var/lock/subsys/notes
;;
stop)
echo -n "Shutting down Lotus Domino server: "
su notes -c /opt/lotus/bin/stop_server
rm -f /var/lock/subsys/notes
echo
;;
restart|reload)
$0 stop
$0 start
;;
*)
echo "Usage: notes {start|stop|restart|reload}"
exit 1
esac

exit 0
6. サーバパスワードのファイル準備
サーバIDにパスワードが設定している場合は、 下記のファイルへパスワードを記述します。

/local/notesdata/.passwd
<サーバIDのパスワード>
7. スタートアップファイルの登録
シェルスクリプトのシンボリックをランレベルに合わせ作成します。
> cd /etc/rc.d/rc3.d
> ln -fs ../init.d/notes S99notes
> cd /etc/rc.d/rc5.d
> ln -fs ../init.d/notes S99notes
> cd /etc/rc.d/rc0.d
> ln -fs ../init.d/notes K99notes
> cd /etc/rc.d/rc6.d
> ln -fs ../init.d/notes K99notes
これで、自動起動/停止されるはずです。 リブートするまえに下記のように一旦テストしてみてください。 手動にて起動する場合は下記のようにします。
> cd /etc/rc.d/init.d
> ./notes start
停止する場合は下記のようにします。
> cd /etc/rc.d/init.d
> ./notes stop
最後は実際に再起動及び停止してみて、自動起動・停止の機能が効いているか確認し完了します。

※注意: 再起動/停止する際は init コマンドを使用します。 reboot/shutdownだと適切な終了処理を行ないません。



[ >>Next ]

| ドミノLinux対応版の構築・運用 メニューへ |


Takuya Fujinami
Most recent update : March 1,2002