_supervisorctl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #compdef supervisorctl
  2. typeset -A opt_args
  3. local context state line
  4. _supervisorctl() {
  5. _arguments -s -S \
  6. {--configuration,-c}"[configuration file path (default /etc/supervisor.conf)]:FILENAME:_files" \
  7. {--help,-h}"[print usage message and exit]:" \
  8. {--interactive,-i}"[start an interactive shell after executing commands]" \
  9. {--serverurl,-s}"[URL on which supervisord server is listening (default "http://localhost:9001").]" \
  10. {--username,-u}"[username to use for authentication with server]:USERNAME:_users" \
  11. {--password,-p}"[password to use for authentication with server]:PASSWORD:" \
  12. {--history-file,-r}"[keep a readline history (if readline is available)]:FILENAME:_files" \
  13. "*::supervisorctl commands:_supervisorctl_command"
  14. }
  15. (( $+functions[_supervisorctl_command] )) ||
  16. _supervisorctl_command() {
  17. local cmd ret=1
  18. (( $+supervisorctl_cmds )) || _supervisorctl_cmds=(
  19. "add:Activates any updates in config for process/group" \
  20. "avail:Display all configured processes" \
  21. "clear:Clear process/multiple-process/all-process log files" \
  22. "exit:Exit the supervisor shell." \
  23. "fg:Connect to a process in foreground mode" \
  24. "maintail:tail of supervisor main log file" \
  25. "open:Connect to a remote supervisord process. (for UNIX domain socket, use unix:///socket/path)" \
  26. "pid:Get the PID of supervisord." \
  27. "quit:Exit the supervisor shell." \
  28. "reload:Restart the remote supervisord." \
  29. "remove:Removes process/group from active config" \
  30. "reread:Reload the daemon's configuration files" \
  31. "restart:Restart process or group." \
  32. "shutdown:Shut the remote supervisord down." \
  33. "start:Start process or groups." \
  34. "status:Get process status info." \
  35. "stop:Stop process or group." \
  36. "tail:tail of process stdout" \
  37. "update:Reload config and add/remove as necessary" \
  38. "version:Show the version of the remote supervisord process" \
  39. "help:Show help" \
  40. )
  41. if (( CURRENT == 1 )); then
  42. _describe -t commands 'supervisorctl subcommand' _supervisorctl_cmds \
  43. || compadd "$@" - ${(s.:.)${(j.:.)_supervisorctl_syns}}
  44. else
  45. local curcontext="$curcontext"
  46. cmd="${${_supervisorctl_cmds[(r)$words[1]:*]%%:*}:-${(k)_supervisorctl_syns[(r)(*:|)$words[1](:*|)]}}"
  47. if (( $#cmd )); then
  48. curcontext="${curcontext%:*:*}:supervisorctl-${cmd}:"
  49. _call_function ret _supervisorctl_$cmd || _message 'no more arguments'
  50. else
  51. _message "unknown supervisorctl command: $words[1]"
  52. fi
  53. return ret
  54. fi
  55. }
  56. # get supervisor contoroll processes
  57. (( $+functions[_get_supervisor_procs] )) ||
  58. _get_supervisor_procs() {
  59. local cache_policy
  60. zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  61. if [[ -z "$cache_policy" ]]; then
  62. zstyle ":completion:${curcontext}:" cache-policy _supervisor_procs_caching_policy
  63. fi
  64. if ( [[ ${+_supervisor_procs} -eq 0 ]] || _cache_invalid supervisor_procs ) \
  65. && ! _retrieve_cache supervisor_procs; then
  66. _supervisor_procs=(${${(f)"$(supervisorctl status >/dev/null 2>&1 | awk -F' ' '{print $1}')"}})
  67. _store_cache supervisor_procs _supervisor_procs
  68. fi
  69. local expl
  70. _wanted supervisor_procs expl 'supervisor processes' compadd -a _supervisor_procs
  71. }
  72. _supervisor_procs_caching_policy() {
  73. local -a oldp
  74. oldp=( "$1"(Nmw+1) )
  75. (( $#oldp ))
  76. }
  77. (( $+functions[_supervisorctl_add] )) ||
  78. _supervisorctl_add() {
  79. _arguments -s \
  80. "--help[use help system]" \
  81. "*::supervisorctl commands:_supervisorctl"
  82. }
  83. (( $+functions[_supervisorctl_help] )) ||
  84. _supervisorctl_help() {
  85. _arguments -s \
  86. "*:supervisorctl commands:_supervisorctl"
  87. }
  88. (( $+functions[_supervisorctl_maintail] )) ||
  89. _supervisorctl_maintail() {
  90. _arguments -s \
  91. '-f[Continuous tail of supervisor main log file (Ctrl-C to exit)]'
  92. }
  93. (( $+functions[_supervisorctl_start] )) ||
  94. _supervisorctl_start() {
  95. # TODO: add 'all'
  96. _arguments -s \
  97. '*::supvervisor process:_get_supervisor_procs'
  98. }
  99. (( $+functions[_supervisorctl_status] )) ||
  100. _supervisorctl_status() {
  101. _arguments \
  102. '*::supvervisor process:_get_supervisor_procs'
  103. }
  104. (( $+functions[_supervisorctl_stop] )) ||
  105. _supervisorctl_stop() {
  106. # TODO: add 'all'
  107. _arguments -s \
  108. '*::supvervisor process:_get_supervisor_procs'
  109. }
  110. (( $+functions[_supervisorctl_tail] )) ||
  111. _supervisorctl_tail() {
  112. # TODO: add 'stderr'
  113. _arguments -s \
  114. '-f[Continuous tail of named process stdout Ctrl-C to exit.]' \
  115. '*::supvervisor process:_get_supervisor_procs'
  116. }
  117. _supervisorctl "$@"