วันศุกร์, ตุลาคม 06, 2549

วันนี้เข้า TLWG Planet ตั้งหลายรอบ.. ทีแรกนึุกว่าไม่มีใครอัพเดต blog ตัวเอง
หรือว่ามาจาก cache ของ firefox ..แต่คงไม่มั้ง..เพราะเพิ่งเคลียร์ไปวันสองวัน..
ตั้งไว้ก็ไม่ได้เยอะแยะอะไร..ด้วยความขี้เกียจ..เลยไม่ได้เคลียร์ใหม่..เข้าไปเข้ามา..เอ๊ะ..รู้สึกเว็บเงียบเกิ๊นนน..
พอดีอยู่บน windows เลยรัน ie ..อ้าว..เหตุเพราะ cache กรำส์ - -"

ANYWAY..

ใครเป็น admin คงได้ยุ่งกับอะไรใน /etc/init.d/ กันพอสมควรแหละนะ..
ปกติชาวบ้านก็คงใช้ bash หรือ sh อะไรพวกนี้ไว้เขียน..
...ซึ่งเขียน shell ลวกๆก็จะได้ออกมาประมาณนี้..

!/bin/bash
start_my_program=/usr/local/my_program/startup.sh
stop_my_program=/usr/local/my_program/shutdown.sh
start() {
su -c ${start_my_program} - root
}
stop() {
${stop_my_program}
}
case "$1" in
start)
start_my_program
;;
stop)
stop_my_program
;;
restart)
stop_my_program
sleep 10
start_my_program
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0


จะว่าไปแล้วก็ใช้งานได้(อย่างปกติสุข)อยู่ทุกวัน..

แต่ถ้าใครอยากเปลี่ยน trend ด้วยเหตุผลอันใดก็ตาม..
มาลองใช้ Ruby ดูก็ได้นะ...
ก็จะได้ template ประมาณนี้...

#!/usr/bin/env ruby
require 'timeout'
PROG_NAME = 'my_program'
startup = `/usr/local/bin/ruby /home2/system/start_my_program.rb > start_my_program.log`
stop = `/usr/local/bin/ruby /home2/system/stop_my_program.rb > stop_my_program.log`
case ARGV.first
when 'start':
startup
when 'stop':
stop
when 'restart':
stop
timeout(5)
start
end
unless %w{start stop restart status}.include? ARGV.first
puts "Usage: #{PROG_NAME} {start|stop|restart}"
exit
end


แต่..เพื่ออะไร.. (- -') แฮะ..

ไม่เป็นไร.. Just For FUN.. I LOVE RUBY

1 ความคิดเห็น:

ไม่ระบุชื่อ กล่าวว่า...

ชอบๆ