@@ -198,7 +198,16 @@ def reloadConfig(self):
198198 added = [group .name for group in added ]
199199 changed = [group .name for group in changed ]
200200 removed = [group .name for group in removed ]
201- return [[added , changed , removed ]] # cannot return len > 1, apparently
201+
202+ coll_added , coll_changed , coll_removed = \
203+ self .supervisord .diff_collections_to_active ()
204+
205+ coll_added = [c .name for c in coll_added ]
206+ coll_changed = [c .name for c in coll_changed ]
207+ coll_removed = [c .name for c in coll_removed ]
208+
209+ return [[added , changed , removed ],
210+ [coll_added , coll_changed , coll_removed ]]
202211
203212 def addProcessGroup (self , name ):
204213 """ Update the config for a running process from config file.
@@ -917,6 +926,128 @@ def sendProcessStdin(self, name, chars):
917926
918927 return True
919928
929+ # Collection API methods
930+
931+ def listCollections (self ):
932+ """ Get info about all configured collections.
933+
934+ @return array result An array of collection info structs
935+ """
936+ self ._update ('listCollections' )
937+ result = []
938+ for coll in self .supervisord .collections .values ():
939+ result .append ({
940+ 'name' : coll .config .name ,
941+ 'priority' : coll .config .priority ,
942+ 'program_names' : coll .config .program_names ,
943+ 'group_names' : coll .config .group_names ,
944+ })
945+ return result
946+
947+ def getCollectionProcessInfo (self , name ):
948+ """ Get info about all processes in a collection named name.
949+
950+ @param string name The name of the collection
951+ @return array result An array of process status results
952+ """
953+ self ._update ('getCollectionProcessInfo' )
954+
955+ collection = self .supervisord .collections .get (name )
956+ if collection is None :
957+ raise RPCError (Faults .BAD_NAME , name )
958+
959+ output = []
960+ seen = set ()
961+ for group , process in collection .get_processes ():
962+ key = (group .config .name , process .config .name )
963+ if key not in seen :
964+ seen .add (key )
965+ namespec = make_namespec (group .config .name ,
966+ process .config .name )
967+ output .append (self .getProcessInfo (namespec ))
968+ return output
969+
970+ def startCollection (self , name , wait = True ):
971+ """ Start all processes in the collection named 'name'
972+
973+ @param string name The collection name
974+ @param boolean wait Wait for each process to be fully started
975+ @return array result An array of process status info structs
976+ """
977+ self ._update ('startCollection' )
978+
979+ collection = self .supervisord .collections .get (name )
980+ if collection is None :
981+ raise RPCError (Faults .BAD_NAME , name )
982+
983+ seen = set ()
984+ processes = []
985+ for group , process in collection .get_processes ():
986+ key = (group .config .name , process .config .name )
987+ if key not in seen :
988+ seen .add (key )
989+ processes .append ((group , process ))
990+
991+ startall = make_allfunc (processes , isNotRunning , self .startProcess ,
992+ wait = wait )
993+ startall .delay = 0.05
994+ startall .rpcinterface = self
995+ return startall # deferred
996+
997+ def stopCollection (self , name , wait = True ):
998+ """ Stop all processes in the collection named 'name'
999+
1000+ @param string name The collection name
1001+ @param boolean wait Wait for each process to be fully stopped
1002+ @return array result An array of process status info structs
1003+ """
1004+ self ._update ('stopCollection' )
1005+
1006+ collection = self .supervisord .collections .get (name )
1007+ if collection is None :
1008+ raise RPCError (Faults .BAD_NAME , name )
1009+
1010+ seen = set ()
1011+ processes = []
1012+ for group , process in collection .get_processes ():
1013+ key = (group .config .name , process .config .name )
1014+ if key not in seen :
1015+ seen .add (key )
1016+ processes .append ((group , process ))
1017+
1018+ killall = make_allfunc (processes , isRunning , self .stopProcess ,
1019+ wait = wait )
1020+ killall .delay = 0.05
1021+ killall .rpcinterface = self
1022+ return killall # deferred
1023+
1024+ def signalCollection (self , name , signal ):
1025+ """ Send a signal to all processes in the collection named 'name'
1026+
1027+ @param string name The collection name
1028+ @param string signal Signal to send, as name ('HUP') or number ('1')
1029+ @return array
1030+ """
1031+ self ._update ('signalCollection' )
1032+
1033+ collection = self .supervisord .collections .get (name )
1034+ if collection is None :
1035+ raise RPCError (Faults .BAD_NAME , name )
1036+
1037+ seen = set ()
1038+ processes = []
1039+ for group , process in collection .get_processes ():
1040+ key = (group .config .name , process .config .name )
1041+ if key not in seen :
1042+ seen .add (key )
1043+ processes .append ((group , process ))
1044+
1045+ sendall = make_allfunc (processes , isSignallable , self .signalProcess ,
1046+ signal = signal )
1047+ result = sendall ()
1048+ self ._update ('signalCollection' )
1049+ return result
1050+
9201051 def sendRemoteCommEvent (self , type , data ):
9211052 """ Send an event that will be received by event listener
9221053 subprocesses subscribing to the RemoteCommunicationEvent.
0 commit comments