Running Workerman as a service at Alpine Linux
在Alpine Linux上运行基于Workerman的服务

/etc/init.d/generate_204

#!/sbin/openrc-run

name="generate_204"
command="/usr/bin/php /root/generate_204/main.php"
command_background="yes"
depend() {
        need net
}
start() {
        ${command} start -d
}

stop() {
        ${command} stop
}

status() {
        ${command} status
}
crazy:~# chmod +x /etc/init.d/generate_204
crazy:~# rc-update add generate_204
 * service generate_204 added to runlevel default
crazy:~# rc-service generate_204 start
Workerman[/root/generate_204/main.php] start in DAEMON mode
------------------------------------------- WORKERMAN --------------------------------------------
Workerman version:4.1.6          PHP version:8.1.16           Event-Loop:\Workerman\Events\Select
-------------------------------------------- WORKERS ---------------------------------------------
proto   user            worker          listen                 processes    status           
tcp     root            generate_204    http://0.0.0.0:2333    1             [OK]            
--------------------------------------------------------------------------------------------------
Input "php /root/generate_204/main.php stop" to stop. Start success.
crazy:~# netstat -anp | grep php
tcp        0      0 0.0.0.0:2333            0.0.0.0:*               LISTEN      2285/main.php

参考资料:

  1. https://github.com/OpenRC/openrc/blob/master/service-script-guide.md
  2. https://www.workerman.net/doc/workerman/

最后修改于 Thu, 23 Feb 2023