init.dスクリプトを作成

/etc/init.d/ 以下に配置するプロセス起動ファイルを作成

# vi /etc/init.d/myruner
# chkconfig: 345 99 01
# description: my init.d file

# chkconfig: runlevel 起動順番 終了順番
chkconfig --add serviceでrc.dにリンク貼る定義がこれ。

実行ユーザ、コマンドパス、実行ファイル名を指定して、バックグラウンドで実行。
プロセスの終了はpkill, 確認はpgrepの手抜き。

サンプルは以下。

#!/bin/sh
# chkconfig: 345 99 01
# description: my init.d file

SERVICE=myruner
USER=linuxurser
DIR=/your_command_dir/
FILE=your_command_file
COMMAND=$DIR$FILE
start() {
    su -l $USER -c $COMMAND &
    echo "service $SERVICE [start]"
}
stop() {
    pkill $FILE
    echo "service $SERVICE [stop]"
}
status() {
   PID=`pgrep $FILE | wc -l`
   if [ $PID -eq 0 ]; then
       echo "$SERVICE stop"
   else
       echo "running $SERVICE ..."
   fi
}

case $1 in
start)
       start
       ;;
stop)
       stop
       ;;
status)
       status
       ;;
restart)
       stop
       start
       ;;
*)
       echo "Usage: $SERVICE [start|stop|restart|status]"
       ;;
esac
exit 0

/etc/init.d/ で以下に配置後、

# chkconfig --add myruner

で、設定ランレベルシンボリックリンクを作成