Solr 검색엔진을 데몬으로 등록 (update-rc.d)

Apache Solr 를 사용하는중에 시스템이 재부팅되면 다시 시작하는게 귀찮아서

구글링을 해보니 데몬으로 등록하는 방법이 있어 스크랩한다.

 

데몬설치

# sudo su

# apt-get install daemon

 

시작스크립트 생성

# cd /etc/init.d/

# cat > solr

[bash]
#!/bin/sh

# Prerequisites:
# 1. Solr needs to be installed at /usr/local/solr/example
# 2. daemon needs to be installed
# 3. Script needs to be executed by root

# This script will launch Solr in a mode that will automatically respawn if it
# crashes. Output will be sent to /var/log/solr/solr.log. A pid file will be
# created in the standard location.

start () {
echo -n "Starting solr…"

# start daemon
daemon –chdir=’/usr/local/solr/example’ –command "java -jar start.jar" –respawn –output=/var/log/solr/solr.log –name=solr –verbose

RETVAL=$?
if [ $RETVAL = 0 ]
then
echo "done."
else
echo "failed. See error code for more information."
fi
return $RETVAL
}

stop () {
# stop daemon
echo -n "Stopping solr…"

daemon –stop –name=solr –verbose
RETVAL=$?

if [ $RETVAL = 0 ]
then
echo "done."
else
echo "failed. See error code for more information."
fi
return $RETVAL
}

restart () {
daemon –restart –name=solr –verbose
}

status () {
# report on the status of the daemon
daemon –running –verbose –name=solr
return $?
}

case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: solr {start|status|stop|restart}"
exit 3
;;
esac

exit $RETVAL
[/bash]

# update-rc.d solr defaults

중간에 solr가 설치되어 있는 폴더를 변경해줘야 한다.

 

logrotate 등록

# cd /etc/logrotate.d
# cat > solr

[bash]
/var/log/solr/*.log {
  weekly
  rotate 12
  compress
  delaycompress
  create 640 root root
  postrotate
    /etc/init.d/solr restart
  endscript
}
[/bash]

 

답글 남기기