しばらく前にこれに関する内容を読んだようですが、どうなったのか覚えていません。デフォルトでは、/etc/init.d
起動時に自動的に起動したいサービスがあります。スクリプトをディレクトリにシンボリックリンクすることに関連していたと思います/etc/rc.d
が、今は覚えていません。このコマンドは何ですか?
私はFedora / CentOS派生製品を使用していると思います。
ベストアンサー1
前述のようにRed Hatベースのシステムを使用している場合は、次のことができます。
- スクリプトを生成してここに入れます
/etc/init.d
(例/etc/init.d/myscript
:)。スクリプトの形式は次のとおりです。
#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....
# Source function library.
. /etc/init.d/functions
start() {
# code to start app comes here
# example: daemon program_name &
}
stop() {
# code to stop app comes here
# example: killproc program_name
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
# code to check status of app comes here
# example: status program_name
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0
フォーマットは非常に標準的なので、で使用できます。その後、次/etc/init.d
のスクリプトを使用できます。マニュアルページでは、スクリプトのタイトルについて説明します。/etc/init.d/myscript start
chkconfig myscript start
ckconfig
> This says that the script should be started in levels 2, 3, 4, and
> 5, that its start priority should be 20, and that its stop priority
> should be 80.
次に定義するヘルパー関数の開始、停止、およびステータスコードの使用例/etc/init.d/functions
スクリプトの有効化
$ chkconfig --add myscript $ chkconfig --level 2345 myscript on
スクリプトが実際に有効になっていることを確認してください。 「on」を選択したレベルが表示されます。
$ chkconfig --list | grep myscript