Ubuntu下编写 goAgent 服务


Ubuntu下编写 goAgent 服务

  1. #!/bin/sh   
  2.   
  3. # goagent service by liuzhijun   
  4.   
  5. start(){   
  6.    echo "start goagent"  
  7.   
  8.    python /usr/local/share/goagent/local/proxy.py   
  9.   
  10.    exit 0  
  11.   
  12. }   
  13.   
  14. stop(){   
  15.        echo "stop goagent"  
  16.        ps -le |grep python |awk '{print $4}'| xargs kill -9  
  17. }   
  18.   
  19.   
  20. restart(){   
  21.   echo "restart goagent"  
  22.   stop   
  23.   start   
  24. }   
  25.   
  26. case "$1" in   
  27.   
  28. start)   
  29.    start   
  30.    ;;   
  31. stop)   
  32.    stop   
  33.    ;;   
  34. restart)   
  35.    restart   
  36.    ;;   
  37. *)   
  38.   
  39. echo "usage:$0 start|stop|restart"  
  40.   
  41. exit 0;   
  42.   
  43. esac  

几点说明:
0、goagent 是什么你懂的
1、在stop方法中不要写exit 0,否则在重启时,执行完stop方法后就退出了,没有机会执行start
2、编写完脚本后修改其属性为可执行 文件:  chmod a+x  goagent
3、此脚本是以杀掉所有Python进程来结束goagent进程,所以 如果系统中还运行有其他python的程序,此脚本不适用。
4、如果需要开机启动,可以执行命令:sudo update-rc.d goagent defaults 99
取消开机启动: sudo update-rc.d -f goagent remove

相关内容

    暂无相关文章