Container Cloud: configure automatic service startup
Published: 2019-07-26
[West.cn image] By default, supervisor is used to manage startup programs. sshd has already been installed and configured by default. If you have your own program that needs to start automatically when the container starts, please follow the tutorial below to set it up.
For example, the command to start BaoTa Panel is supervisorctl start bt: (If it does not work, first run: rm -rf /www/server/panel/logs/panel.pid)
For non-[West.cn image], please refer to the instructions at the end of this tutorial.
Centos system configuration file directory /etc/supervisord.d/, file suffix is ini
Ubuntu, Debian system configuration file directory /etc/supervisor/conf.d/, file suffix is conf
This tutorial uses nginx as an example.
1. First install and configure the application. Compiling and installing, yum, or apt-get are all acceptable. Installation steps are omitted.
2. Create a configuration file
centos: /etc/supervisord.d/nginx.ini
Ubuntu, Debian: /etc/supervisor/conf.d/nginx.conf
[program:nginx] command=/usr/sbin/nginx -c /etc/nginx/nginx.conf -g 'daemon off;' autorestart=True
3. Update the configuration file
Enter the command supervisorctl update in the terminal
root@e9f9b9578ebb:/# supervisorctl update nginx: added process group
4. Check status
Enter the command supervisorctl status in the terminal
root@e9f9b9578ebb:/# supervisorctl status nginx RUNNING pid 440, uptime 0:00:37 sshd RUNNING pid 26, uptime 0:41:50
The status RUNNING means it is running.
Common supervisroctl commands
supervisorctl stop nginx # stop nginx supervisorctl start nginx # start nginx supervisorctl restart nginx # restart nginx supervisorctl stop all # stop all processes supervisorctl start all # start all processes supervisorctl restart all # restart all processes supervisorctl reload # reload supervisor supervisorctl status # view service status supervisorctl update # update supervisor, generally after adding or modifying startup configuration files, run this command for it to take effect
Common program startup configuration files (please use your actual file paths)
apache
[program:httpd] command=/usr/sbin/httpd -D FOREGROUND autorestart=True
mysql
[program:mysqld] command=/usr/bin/pidproxy /tmp/mysqld.pid /usr/sbin/mysqld_safe --datadir=/home/mysql_data --pid-file=/tmp/mysqld.pid autorestart=True user=mysql
redis
[program:redis] command=/usr/local/bin/redis-server /etc/redis.conf autorestart=True
tomcat
[program:tomcat] directory=/www/server/tomcat/bin command=/www/server/tomcat/bin/catalina.sh run autorestart=True
If not using [West.cn image], please log in to the container management page and find the startup command

If the startup command is a script file, find that script in the container, and add the command line of the program that needs to start with the container to this startup script.
