1. Supervisor is a small system that can manage and monitor various processes in UNIX-like systems. Supervisor’s configuration file is a Windows-INI-style (Python ConfigParser) file.
2. The program configuration section in Supervisor’s configuration file
; * 为必选项
;[program:theprogramname]
;command=/bin/cat ; * 要执行的命令路径(可以是相对与 PATH 的路径)也可带参数
;startsecs=1 ; 需要考虑进程启动成功的时间, 当 running 状态超过该值时,表明启动成功 (def. 1)
;autorestart=unexpected ; 当进程退出时是否应该重启,可选值为 false true unexpected ,为 false 时表示不重启,为 true 表示重启,为 unexpected 时,如果退出状态码不是 exitcodes 中之一时进行重启 (def: unexpected)
;stopwaitsecs=10 ; 这个是当我们向子进程发送 stopsignal 信号后,到系统返回信息给 supervisord,所等待的最大时间。超过这个时间,supervisord会向该子进程发送一个强制 kill 的信号。(default 10)
;stdout_logfile=/a/path ; 进程 stdout 输出的日志文件路径,如果将其设置为NONE,则supervisord将不创建任何日志文件; default AUTO
;stderr_logfile=/a/path ; 除非redirect_stderr为true,否则将进程 stderr 输出放在此文件中。日志文件路径,如果将其设置为NONE,则supervisord将不创建任何日志文件; default AUTO
3. Create \build\c_files\etc\supervisord.d\yii-task-submit.ini, as shown in Figure 1

[program:yii-task-submit]
command = php /sobey/www/aims-rpc/yii task/submit
autorestart = true
startsecs = 0
stopwaitsecs = 10
stderr_logfile = /data/logs/yii-task-submit-stderr.log
stdout_logfile = /data/logs/yii-task-submit-stdout.log
4. stopwaitsecs: the number of seconds to wait for the operating system to return a SIGCHLD to supervisord after the program has been sent a stop signal. If this number of seconds elapses before supervisord receives a SIGCHLD from the process, supervisord will attempt to terminate it with a final SIGKILL. The command is now executed at a default interval of 1 second. For example, if the script execution time is 20 seconds, the interval will be 21 seconds.
5. I found that the result did not meet expectations after the command executed. I entered the container command line and checked /data/logs/yii-task-submit-stderr.log
Exception 'yii\httpclient\Exception' with message 'Curl error: #6 - Could not resolve host: AIMS_RPC_CFG_AI_API_HOST_INFOAIMS_RPC_CFG_AI_API_BASE_URL; Name or service not known'
in /sobey/www/aims-rpc/vendor/yiisoft/yii2-httpclient/src/CurlTransport.php:57
Stack trace:
#0 /sobey/www/aims-rpc/vendor/yiisoft/yii2-httpclient/src/Client.php(221): yii\httpclient\CurlTransport->send(Object(yii\httpclient\Request))
#1 /sobey/www/aims-rpc/vendor/yiisoft/yii2-httpclient/src/Request.php(421): yii\httpclient\Client->send(Object(yii\httpclient\Request))
#2 /sobey/www/aims-rpc/common/logics/http/ai_api/Task.php(63): yii\httpclient\Request->send()
#3 /sobey/www/aims-rpc/console/services/TaskService.php(233): common\logics\http\ai_api\Task->getQueryReady()
#4 /sobey/www/aims-rpc/console/services/TaskService.php(33): console\services\TaskService->getAiQueryReady()
#5 /sobey/www/aims-rpc/console/controllers/TaskController.php(43): console\services\TaskService->submit()
#6 [internal function]: console\controllers\TaskController->actionSubmit()
#7 /sobey/www/aims-rpc/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /sobey/www/aims-rpc/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#9 /sobey/www/aims-rpc/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('submit', Array)
#10 /sobey/www/aims-rpc/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('submit', Array)
#11 /sobey/www/aims-rpc/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('task/submit', Array)
#12 /sobey/www/aims-rpc/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('task/submit', Array)
#13 /sobey/www/aims-rpc/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#14 /sobey/www/aims-rpc/yii(23): yii\base\Application->run()
#15 {main}
6. After resolving the Rancher environment variable substitution issue, I upgraded again. The result met expectations after the command executed, but the output of some string print messages from the command did not wrap automatically, resulting in poor readability. I checked /data/logs/yii-task-submit-stderr.log, as shown in Figure 2

Status: 1 task of 1 (pending submission): None Fetched Status: 1 task of 1 (pending submission): None Fetched Status: 1 task of 1 (pending submission): None Fetched Status: 1 task of 1 (pending submission): None Fetched Status: 1 task of 1 (pending submission): None Fetched Status: 1 task of 1 (pending submission): None Fetched Status: 1 task of 1 (pending submission): None
7. Checking /data/logs/yii-task-submit-stdout.log, it wraps automatically by default
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
Could not open input file: /sobey/www/aims-rpc/yii
8. Edit \console\controllers\TaskController.php to add a newline character when outputting a message
/**
* 调用AI接口:提交任务
* 任务描述:
* 1、查询任务队列是否空闲,如果否,则退出;
* 2、获取1条任务,其条件与排序规则如下:
* (1)任务,状态:1(待提交);
* (2)租户优先级,状态:1(启用);
* (3)排序规则:group_pri.group_pri(顺序),group_pri.group_pri_updated_at(倒序),task.pri(顺序),task.pri_updated_at(倒序),task.created_at(顺序);
* 3、获取1条任务,如果无,则退出;
* 4、获取当前任务的人工智能服务提交日志,如果为空,则提交,否则重做;
* 5、人工智能服务:提交任务/重做任务;
* 6、操作数据(事务)
* (1)创建MySQL模型(人工智能服务提交日志);
* (2)更新任务模型的状态:2(已提交),人工智能服务任务状态:1(处理中);
* (3)创建MySQL模型(人工智能服务任务进度);
*/
public function actionSubmit()
{
$service = new TaskService();
$submitResult = $service->submit();
if ($submitResult['status'] === false) {
$this->stderr($submitResult['message'] . "\n");
return $submitResult['code'];
}
return ExitCode::OK;
}
9. After upgrading, I checked /data/logs/yii-task-submit-stderr.log again; it now wraps automatically, as shown in Figure 3

Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
Fetched status: 1 task of 1 (pending submission): None
