Process Management
Process Management in FreePBX is handled by a central module. This module takes care of managing long running/background processes such as:
Zulu
UCP Node
XMPP (Let's Chat)
Rest Apps
Queue Callback (VQPlus)
There are several core methods when using the Process Management module. Keep in mind that the Process Management module uses the nodejs library called PM2 https://github.com/Unitech/pm2
This does not mean your app has to be written in Node. In fact PM2 supports various formats for starting background processes.
There a five main methods to using PM2 in your application
Start
This method starts your application in the background. Your name must be unique! We suggest using your module's rawname or your module's rawname with a suffix
/**
* Start a process
* @method start
* @param string $name The name of the application
* @param string $process The process to run
* @return mixed Output of getStatus
*/
public function start($name, $process) { |
FreePBX::PM2()->start("modulerawname-suffix","path to script"); |
Your application will be started in the directory where your script lives
Stop
To stop an application you need to simply provide the application name you declared in the start method.
Stopping an application does not remove it from the application list. Instead it puts the application in a "stopped" (non running) state. To remove an application from the list of applications you will need to use the delete method.
/**
* Stop process
* @method stop
* @param string $name The application name
*/
public function stop($name) { |
Delete
This will stop AND delete an application from the list of applications (retrieved from listProcesses).
This method should be used when uninstalling your module
Restart
This method will restart your application which will also increase the restart counter. This can only be used if the script was first started with the start method
getStatus
This will get the status of the application by name. If the application is unknown it will return false
listProcesses
List Processes is similar to getStatus except it will return a list of all processes/applications currently under the control of PM2