Thank you ChetanM... check this out modified script to stop Thin
Cluster...
Cleaner Thin Stop Script create a file called my_stop.sh in the root
directory of your rails application.
####################
#!/bin/bash
this_path=`pwd`
pids_path="$this_path/tmp/pids/*.pid"
for thin_pid in $pids_path
do
echo "Stoping Thin Instance $thin_pid"
thin stop -P $thin_pid
done
####################
[dinooz@localhost rails_app1]$ cat my_thin2.sh
thin start -e development -p 3000 -s 3 -d
[dinooz@localhost rails_app1]$ ./my_thin2.sh
Starting server on
0.0.0.0:3000 ...
Starting server on
0.0.0.0:3001 ...
Starting server on
0.0.0.0:3002 ...
[dinooz@localhost rails_app1]$ ls tmp/pids/
thin.3000.pid thin.3001.pid thin.3002.pid
[dinooz@localhost rails_app1]$ pstree -p |grep thin
ââthin(780)
ââthin(784)
ââthin(788)
[dinooz@localhost rails_app1]$ cat tmp/pids/thin.3000.pid
780
[dinooz@localhost rails_app1]$ cat tmp/pids/thin.3001.pid
784
[dinooz@localhost rails_app1]$ cat tmp/pids/thin.3002.pid
788
[dinooz@localhost rails_app1]$ cat my_stop.sh
#!/bin/bash
this_path=`pwd`
pids_path="$this_path/tmp/pids/*.pid"
for thin_pid in $pids_path
do
echo "Stoping Thin Instance $thin_pid"
thin stop -P $thin_pid
done
[dinooz@localhost rails_app1]$ ./my_stop.sh
Stoping Thin Instance /home/dinooz/rails/rails_app1/tmp/pids/thin.
3000.pid
Sending QUIT signal to process 780 ...
Stoping Thin Instance /home/dinooz/rails/rails_app1/tmp/pids/thin.
3001.pid
Sending QUIT signal to process 784 ...
Stoping Thin Instance /home/dinooz/rails/rails_app1/tmp/pids/thin.
3002.pid
Sending QUIT signal to process 788 ...
[dinooz@localhost rails_app1]$ pstree -p |grep thin
[dinooz@localhost rails_app1]$ ls tmp/pids/
[dinooz@localhost rails_app1]$
All Thin Processes attached to that particular application have been
killed and the files removed.
PROS:
1.- No hard coded ports required to start or stop the Thin Cluster
Instances
2.- With a simple shell script can change directory to the particular
rails app and execute my_stop.sh
TODO:
1.- Create a [ /etc/thin/app1.cfg ... /etc/thin/app2.cfg ... ] where
each configuration file include the definition of the Thin Cluster.
then can be started with /etc/init.d/thin start this will read the
files located in [ /etc/thin/app1.cfg ... /etc/thin/app2.cfg .. ] and
start each of the instances for each of the rails applications.
Best Regards Din00z.