歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu下編寫 goAgent 服務

Ubuntu下編寫 goAgent 服務

日期:2017/2/28 15:42:18   编辑:Linux教程

Ubuntu下編寫 goAgent 服務

  1. #!/bin/sh
  2. # goagent service by liuzhijun
  3. start(){
  4. echo "start goagent"
  5. python /usr/local/share/goagent/local/proxy.py
  6. exit 0
  7. }
  8. stop(){
  9. echo "stop goagent"
  10. ps -le |grep python |awk '{print $4}'| xargs kill -9
  11. }
  12. restart(){
  13. echo "restart goagent"
  14. stop
  15. start
  16. }
  17. case "$1" in
  18. start)
  19. start
  20. ;;
  21. stop)
  22. stop
  23. ;;
  24. restart)
  25. restart
  26. ;;
  27. *)
  28. echo "usage:$0 start|stop|restart"
  29. exit 0;
  30. 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

Copyright © Linux教程網 All Rights Reserved