2007年1月3日 星期三

AutoRun Way in Linux (2) - non-root execute

使用非root的身分執行程式,ex: testuser
#!/bin/bash
#chkconfig: 35 98 05
#description:testserver
case "$1" in
  start)
     su - testuser -c "cd /usr/testserver/;./TestServer > /dev/null &"

     sleep 3
     su - testuser -c "cd /usr/testserver2/;./TestServer > /dev/null &"
     exit 0
     ;;
  stop)
     cd /usr/testserver/TestServer
     test -e ./TestServer_pid && cat TestServer_pid |xargs kill -15 ||echo "no _pid file"
     exit 0
     ;;
esac
echo "usage:testserver {startstop}"
exit 1


沒有留言: