Install Supervisor For A PHP Script

Server environment

1
2
3
4
5
$ cat /etc/issue
Ubuntu 14.04.5 LTS

$ supervisord -v
3.0b2

Install Supervisor

1
$ sudo apt-get install -y supervisor

Add A New Supervisor Config File

1
$ sudo vim /etc/supervisor/conf.d/php-script.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[program:updateGoods]
directory = /www
command=/usr/bin/php bin/console update:goods
process_name = %(program_name)s_%(process_num)02d
numprocs = 1
autostart=true
autorestart=true
startsecs=1
startretries=3
exitcodes = 0,2
redirect_stderr=true
stopsignal = QUIT
stopwaitsecs = 10
stopasgroup=true
stdout_logfile=/www/log/update.goodes.log
user=daemon
environment = SYMFONY_ENV=prod

[supervisord]
nodaemon=true

[supervisorctl]

Here, I have a Symfony3 project under the /www directory, I hope the supervisor can start running a php script by command php bin/console update:goods
if supervisor startup.
numprocs means it will start one process and stopsignal means that it will send a quit signal to this php process before supervisor stop
nodaemon under [supervisord] is very helpful if you use the docker to manager your container.

Start Supervisor Service

1
$ sudo service supervisor start

Check The PHP running status

1
2
$ sudo supervisorctl status
app:updateGoods_00 RUNNING pid 7, uptime 0:44:12

or you can using this commands to control these process

1
2
3
$ sudo supervisorctl stop app:updateGoods_00
$ sudo supervisorctl start app:updateGoods_00
$ sudo supervisorctl restart app:updateGoods_00

Something wrong i meet

After first time i start the supervisor service. I saw these errors in my project error.
It means that the user (user=daemon) in supervisor config file can not access the /www directory.
So you can update the config user=root to fix this problem

1
2
3
4
5
6
7
8
9
[email protected]:~# tail -f /www/log/update.goodes.log 
supervisor: couldn't chdir to /www: EACCES
supervisor: child process was not spawned
supervisor: couldn't chdir to /www: EACCES
supervisor: child process was not spawned
supervisor: couldn't chdir to /www: EACCES
supervisor: child process was not spawned
supervisor: couldn't chdir to /www: EACCES
supervisor: child process was not spawned

Share