Dovecot の init 書いてみた。

Linux
この記事は約4分で読めます。
この記事は最終更新日より 1 年以上経過しています。
画像やリンクが無効になっている可能性もあるのでご了承下さい。

昨日のリプレースで MRA が Dovecot になった訳だが、ソースからコンパイルしているので
OS 起動時の自動実行プログラムが無い状態。
これだといちいち起動させるのが面倒だし、通常の運用面でも Restart かけるときに面倒だ。

で、init を書いておいた。

とはいっても既に init ファイルのひな形は昔 BIND のやつ書いたときには出来上がっていたので
これを使ってパラメータとメッセージを書き換えただけ。

参考にするのであれば PID とバイナリの位置、conf ファイルを自分の環境に合わせること。

[sh]#!/bin/sh
#
# Dovecot init scripts
# 2007/11/19

# Set variables.
PID=”/var/run/dovecot/master.pid”
BIN=”/usr/local/sbin/dovecot”
CNF=”/usr/local/etc/dovecot.conf”

# Functions
start() {
printf “Dovecot Start: ”
if [ -f ${PID} ]; then
printf “Failed. maybe already running.\n”
else
${BIN} -c ${CNF}
printf “Success\n”
fi
}

stop() {
printf “Dovecot Stop: ”
if [ -f ${PID} ]; then
kill -TERM `cat ${PID}`
printf “Stopped\n”
[ -f ${PID} ] && rm -f ${PID}
else
printf “Dovecot is not running.\n”
exit 1
fi
}

restart() {
printf “Dovecot Restart: ”
if [ -f ${PID} ]; then
kill -HUP `cat ${PID}`
printf “Success\n”
else
printf “Dovecot is not running.\n”
exit 1
fi
}

status() {
if [ -f ${PID} ]; then
printf “Dovecot available.\n”
else
printf “Dovecot is not available.\n”
fi
}

# Main
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
printf “Usage: $0 {start|stop|restart|status}\n”
exit 1
esac

exit $?
[/sh]

(c) BuCCi

著者プロフィール
ぶっち

本格的に PC へ触れ始めてたのは 1990 年位から。
興味は PC 全般。OS は Windows と Linux などを嗜む。
プログラマやネットワークエンジニアを経てフリーに活動している 2 児の父な 40 代半ばのおじさんです。

ぶっちをフォローする

コメント

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.