close
The Wayback Machine - https://web.archive.org/web/20200916002701/https://github.com/kcloze/multiprocess
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

multiprocess

  • [readme in english]
  • 基于swoole的脚本管�?�,用于多进程和守护进程管�?�;
  • �?�轻�?�让普通脚本�?�守护进程和多进程执行;
  • 进程个数�?��?置,�?�以根�?��?置一次性执行多�?�命令;
  • �?进程异常退出时,主进程收到信�?�,自动拉起�?新执行;
  • 支�?�?进程平滑退出,防止�?�?��?务对业务造�?影�?ï¼›
  • �?�?定编程语言,PHP/Python/Java/Golang/C#等脚本都�?�以管�?�

1. 场景

  • PHP/python/js等脚本需�?跑一个或多个脚本消费队列/计算等任务
  • 实现脚本退出�?�自动拉起,防止消费队列�?工作,影�?业务
  • 其实supervisor�?�以轻�?��?�个事情,这个�?�是PHP的�?�一�?实现,�?需�?�?�技术栈

2. �?程图

�?程图

3. 安装

4. �?置实例

  • 一次性执行多个命令
    'logPath'   => __DIR__ . '/log',
    'exec'      => [
        [
            'name'      => 'kcloze-test-1',
            'bin'       => '/usr/bin/php',
            'binArgs'   => [__DIR__ . '/test/test.php', 'oop', '123'],
            'workNum'   => 3,
        ],
        [
            'name'      => 'kcloze-test-2',
            'bin'       => '/usr/bin/php',
            'binArgs'   => [__DIR__ . '/test/test2.php', 'oop', '456'],
            'workNum'   => 5,
        ],
        [
            'name'      => 'kcloze-test-3',
            'bin'       => '/usr/bin/python',
            'binArgs'   => [__DIR__ . '/test/test3.py', 'oop', '369'],
            'workNum'   => 2,
        ],
    ],

5. �?行

5.1 �?�动

  • chmod -R u+r log/
  • php multiprocess.php start >> log/system.log 2>&1

5.2 平滑�?�止�?务,根�?��?进程执行时间等待所有�?务�?�止

  • php multiprocess.php stop

5.3 强制�?�止�?务[慎用]

  • php multiprocess.php exit

5.4 强制�?�?�

  • php multiprocess.php restart >> log/system.log 2>&1

5.5 监控

  • ps -ef|grep 'multi-process'

5.6 �?�动�?�数说明

NAME
      php multiprocess - manage multiprocess

SYNOPSIS
      php multiprocess -s command [options] -c config file path
          Manage multiprocess daemons.


WORKFLOWS


      help [command]
      Show this help, or workflow help for command.

      -s restart
      Stop, then start multiprocess master and workers.

      -s start 
      Start multiprocess master and workers.
      -s start -c ./config
      Start multiprocess with specail config file.


      -s stop
      Wait all running workers smooth exit, please check multiprocess status for a while.

      -s exit
      Kill all running workers and master PIDs.

6. �?务管�?�

�?�动和关闭�?务,有两�?方�?:

6.1 php脚本(主进程挂了之�?�,需�?手动�?�动)

./multiprocess.php start|stop|exit|restart

6.2 使用systemd管�?�(故障�?�?��?开机自�?�动)

更多systemd介�?

1. 根�?�自己项目路径,修改 systemd/multiprocess.service
2. sudo cp -f systemd/multiprocess.service /etc/systemd/system/
3. sudo systemctl --system daemon-reload
4. �?务管�?�
#�?�动�?务
sudo systemctl start multiprocess.service
#reload�?务
sudo systemctl reload multiprocess.service
#关闭�?务
sudo systemctl stop multiprocess.service

7. 系统状�?

监控图

8. change log

2017-11-30

  • 彻底�?æž„v2版本
  • 增加exit�?�动�?�数,默认stop等待�?进程平滑退出

9. 感谢

10. �?�系

qq群:141059677

You can’t perform that action at this time.