I have a ruby process that has to be started on the system boot. So i created the init.d file for it in the /etc/init.d directory
. the file is /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
It starts the process by running the following command
/home/ubuntu/.rvm/gems/ruby-2.1.0/bin/remote_syslog -c /etc/log_files.yml --pid-file /home/ubuntu/remote_syslog.pid
I wrote the upstart script to make sure the process respawn
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
this file is saved as '/etc/init/remote_syslog_upstart.conf'
By checking /tmp/upstart.log
, every second, I learnt, it tries to run the ruby command by calling the init.d script and since it will be already running, the ruby command return saying Already running at /home/ubuntu/remote_syslog.pid.
Now, the problem is, since its executing the ruby command every time, ruby is taking up 99% of CPU and I'm able to do anything else on the system.
This is the first time I'm working with upstart. Am I doing something wrong here.?