2chproxy.pl のサービス化

再起動時に一々手動で上げるのが面倒臭かったので
超お手軽起動スクリプト作成


/etc/init.d/2chproxy を以下で作成

#!/bin/bash
#
# 2chproxy      This shell script takes care of starting and stopping
#               2chproxy (perl script).
#
# chkconfig: 2345 80 02
# description: 2chproxy is the Proxy daemon.

# Source function library.
. /etc/init.d/functions

process=2chproxy
prog=/usr/local/bin/2chproxy.pl
lockfile=/var/lock/subsys/$process

start() {
        echo -n $"Starting $process: "
        $prog -daemon
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch $lockfile
        return $RETVAL
}

stop() {
        [ "$EUID" != "0" ] && exit 4
        echo -n $"Shutting down $process: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f $lockfile
        return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $prog
        ;;
  restart|force-reload)
        stop
        start
        ;;
  reload)
        exit 3
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 2
esac



/etc/init.d/2chproxy の属性変更

# chmod 755 /etc/init.d/2chproxy
# chown root:root /etc/init.d/2chproxy



で、単体での起動確認を実施してから、chkconfig でサービス組込

# /etc/init.d/2chproxy status
2chproxy.pl is stopped
#
# /etc/init.d/2chproxy start
Starting 2chproxy:
#
# /etc/init.d/2chproxy status
2chproxy.pl (pid 2160) is running...
#
# ps -ef | grep 2ch | grep -v grep
root      2160     1  0 14:10 ?        00:00:00 /usr/bin/perl /usr/local/bin/2chproxy.pl -daemon
#
# /etc/init.d/2chproxy stop
Shutting down 2chproxy:                                    [  OK  ]
#
# /etc/init.d/2chproxy status
2chproxy.pl is stopped
#


# chkconfig --add 2chproxy
# chkconfig --list 2chproxy
2chproxy        0:off   1:off   2:on    3:on    4:on    5:on    6:off



後は再起動して、ちゃんと起動してくるかの確認


起動スクリプトが、なんか変な感じなんだけど
perlのお作法がわからんし、一応動いてるからこれで(ヒドい