1

システムの起動時に開始する必要がある ruby​​ プロセスがあります。だから私はそれのために init.d ファイルを作成しました/etc/init.d directory. ファイルは/etc/init.d/remote_syslog

#!/bin/bash
#!/usr/bin/env ruby
#
#       /etc/init.d/remote_syslog
#
# Starts the remote_syslog daemon
#
# chkconfig: 345 90 5
# description: Runs remote_syslog
#
# processname: remote_syslog

[[ -s "/home/ubuntu/.rvm/scripts/rvm" ]] && . "/home/ubuntu/.rvm/scripts/rvm"

source "/home/ubuntu/.rvm/scripts/rvm"

prog="remote_syslog"
config="/etc/log_files.yml"
pid_dir="/home/ubuntu"

EXTRAOPTIONS=""

pid_file="$pid_dir/$prog.pid"


PATH=/home/ubuntu/.rvm/gems/ruby-2.1.0/bin:/home/ubuntu/.rvm/gems/ruby-2.1.0@global/bin:/home/ubuntu/.rvm/rubies/ruby-2.1.0/bin:/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH

RETVAL=0

is_running(){
  [ -e $pid_file ]
}

start(){
    echo -n $"Starting $prog: "

    unset HOME MAIL USER USERNAME
    $prog -c $config --pid-file $pid_file $EXTRAOPTIONS
    RETVAL=$?
    echo
    return $RETVAL
}

stop(){
    echo -n $"Stopping $prog: "
    if (is_running); then
      kill `cat $pid_file`
      RETVAL=$?
      echo
      return $RETVAL
    else
      echo "$pid_file not found"
    fi
}

status(){
    echo -n $"Checking for $pid_file: "

    if (is_running); then
      echo "found"
    else
      echo "not found"
    fi
}

reload(){
    restart
}

restart(){
    stop
    start
}

condrestart(){
    is_running && restart
    return 0
}


# See how we were called.
case "$1" in
    start)
  start
  ;;
    stop)
  stop
  ;;
    status)
  status
  ;;
    restart)
  restart
  ;;
    reload)
  reload
  ;;
    condrestart)
  condrestart
  ;;
    *)
  echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
  RETVAL=1
esac

exit $RETVAL

次のコマンドを実行してプロセスを開始します /home/ubuntu/.rvm/gems/ruby-2.1.0/bin/remote_syslog -c /etc/log_files.yml --pid-file /home/ubuntu/remote_syslog.pid

プロセスが確実に再生成されるように、upstart スクリプトを作成しました。

description "Monitor files and send to remote syslog"
start on runlevel [2345]
stop on runlevel [!2345]


respawn

exec sudo /etc/init.d/remote_syslog start >> /tmp/upstart.log 2>&1

このファイルは「/etc/init/remote_syslog_upstart.conf」として保存されます

をチェックすること/tmp/upstart.logで、毎秒、init.dスクリプトを呼び出してrubyコマンドを実行しようとし、すでに実行されているため、rubyコマンドが次のように返すことがわかりましたAlready running at /home/ubuntu/remote_syslog.pid.

問題は、毎回 ruby​​ コマンドを実行するため、ruby が CPU の 99% を占有し、システムで他のことを実行できることです。

私がupstartと仕事をするのはこれが初めてです。ここで何か間違ったことをしていますか?

4

0 に答える 0