Setup limitation - no systemd on my Docker image

We are planning to deploy ERPNext by leveraging Docker.
We have built a Centos 7 docker container that is used to run the setup script in the same way it has been done by David Gu in this example:
https://hub.docker.com/r/davidgu/erpnext/

Docker container does not enable systemd to run in the container, unless you use certain privileges or loop holes ( see http://developerblog.redhat.com/2014/05/05/running-systemd-within-docker-container/ for more details)

In our case, we have used supervisord in the Docker container to start and stop the different services during the ERPNext installation - I can share the Dockerfile and installation script if you are interested.

At some point during the ERPNext app installation, the frappe framework tries to restart its different services. While doing so, the framework check which service manager is used between systemd and service. If the installation script fails to identify one of those two, then the services are not restarted and the installation is aborted.

Here is my suggestion: It would be great to also check if supervisord is used as a service manager in the installation so that it can support this use case.
Let me know if you have other suggestions or ideas to workaround this issue.

CC: @pdvyas @anand

@dgrelin

I’ve pushed a fix in bench.

You can set an environment variable: export BENCH_SERVICE_MANAGER=‘supervisorctl’ before installing and it should work.

Thanks,
Anand.

Thanks a lot, Anand.
I am going to test it right away and keep you posted.

Didier

Hi Anand,

I have noticed that the fix also uses an addition env variable called BENCH_SERVICE_MANAGER_COMMAND.
So I have set it as well and everything seems to work well until the following error pops up:

Context = (Logged as root in the frappe-bench directory)

echo $BENCH_SERVICE_MANAGER

supervisorctl

echo $BENCH_SERVICE_MANAGER_COMMAND

supervisorctl

bench setup production erpnext

Restarted supervisord
error: <class ‘xmlrpclib.Fault’>, <Fault 6: ‘SHUTDOWN_STATE’>: file: /usr/lib64/python2.7/xmlrpclib.py line: 793

Should I try something differently?

Didier

Actually, in this case, if you’ve setup nginx/mysql/redis, etc via supervisor itself, we can skip calling restat_service('nginx') all together because we do a full supervisor reload just before that, so a feature like SKIP_RESTART_SERVICE would do the job.

If you can share your Dockerfile, I’ll make it working and submit to docker hub as well :smile:

cc: @anand

You don’t need to set the command. It is only in case the command is different from the one supplied.

Yes, that makes sense - no need to restart the service NGinx, you are right, Pratik.

Here is the Dockerfile - feel free to make some adjustments or suggestions before submitting to docker hub:

FROM centos:7

ENV FRAPPE_USER erpnext
ENV HOSTNAME <set your hostname>
ENV BENCH_SERVICE_MANAGER supervisorctl

RUN yum -y update && yum -y clean all && yum update python -y
RUN yum -y install wget ca-certificates sudo rpm-cron python-setuptools MySQL-python httpd mysql mysql-server mysql-devel git memcached ntp vim
RUN easy_install pip && pip install pytz python-dateutil jinja2 markdown2 termcolor python-memcached requests chardet dropbox google-api-python-client pygeoip

RUN easy_install supervisor

# Create a new user for frappe
RUN useradd $FRAPPE_USER && chown -R $FRAPPE_USER.$FRAPPE_USER /home/$FRAPPE_USER && chmod a+x /home/$FRAPPE_USER

#Fix issue with /run write access
RUN chmod a+w /run

WORKDIR /home/$FRAPPE_USER

COPY frappe_passwords.sh /root/frappe_passwords.sh
# Need to preload the supervisord configuration as we use supervisord as a service manager
COPY all.conf /etc/supervisord.d/all.ini

# Copy the updated version of the frappe install script
COPY setup_frappe.sh setup_frappe.sh

# Running an updated version of the Frappe installation script
RUN bash setup_frappe.sh --frappe-user $FRAPPE_USER --setup-production

# Make sure the volume is in sync with the frappe username
VOLUME ["/var/lib/mysql", "/home/erpnext/frappe-bench/sites/<type your sitename here>/"]
EXPOSE 80

CMD ["/usr/bin/supervisord","-n"]
1 Like

Forgot to attach the all.conf file for CentOs7 - which is slightly different from the one published by David Gu for Debian.

all.conf file

[program:mysqld]
command=/usr/bin/pidproxy /var/mysqld.pid /usr/bin/mysqld_safe --pid-file=/var/run/mysqld.pid
autostart=true
autorestart=true
user=root


[program:redis]
command=/usr/bin/redis-server /etc/redis.conf
autostart=true
autorestart=true
user=redis
#stdout_logfile=/var/log/redis/stdout.log
#stderr_logfile=/var/log/redis/stderr.log

[program:crond]
command=/usr/sbin/crond -n
process_name=crond
numprocs=1
directory=/tmp
umask=022
priority=999
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=10
user=root

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
stdout_events_enabled=true
stderr_events_enabled=true
1 Like

Thanks, I’ll try this dockerfile today. Did you get it working?

Hi Pratik,

I still have an error message when completing the installation manually in my Centos7 Docker instance.
When running the last installation step of the setup script, I receive an error message regarding the command to restart NGinx - as you have mentioned earlier, we could skip this step since we do a full supervisor reload just before.

If you provide a feature like SKIP_RESTART_SERVICE, this could be a good workaround.

Here is the full trace:

# bench setup production erpnext
Restarted supervisord
error: <class 'xmlrpclib.Fault'>, <Fault 6: 'SHUTDOWN_STATE'>: file: /usr/lib64/python2.7/xmlrpclib.py line: 793
Traceback (most recent call last):
  File "/usr/bin/bench", line 9, in <module>
    load_entry_point('bench==0.92', 'console_scripts', 'bench')()
  File "/home/erpnext/bench-repo/bench/cli.py", line 60, in cli
    bench()
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/home/erpnext/bench-repo/bench/cli.py", line 456, in setup_production
    _setup_production(user=user)
  File "/home/erpnext/bench-repo/bench/production_setup.py", line 67, in setup_production
    restart_service('nginx')
  File "/home/erpnext/bench-repo/bench/production_setup.py", line 18, in restart_service
    exec_cmd(service_manager_command)
  File "/home/erpnext/bench-repo/bench/utils.py", line 104, in exec_cmd
    raise CommandFailedError(cmd)
bench.utils.CommandFailedError: supervisorctl restart nginx

Pushed. Just set SKIP_RESTART_SERVICE and try again

Thanks, Pratik.
I have tried it in my environment and after a few tries, I realized the variable is actually called “NO_SERVICE_RESTART”.
After setting it to true, it worked like a charm with no error code returned.
I am going to update my Dockerfile to include this change and generate a new image.

Thanks a lot for your support and help,

Didier

1 Like

Oops, sorry for that. Glad it worked. :smile:

@dgrelin Can you push your dockerfile to a repo so that we can officially publish it?

Thanks!

Sure, I need to make a few adjustments to make it generic and remove some custom pieces, like the default site name.
I should have this ready during next week.

1 Like

@dgrelin just stumbled over this thread from some time ago. Have you done a docker file which could be used in the meantime? Would you mind to post the docker repo here?

Hello @pdvyas, I see there’s a huge demand for an official docker setup and I’m interested as well. If I understand correctly you managed to make it working. Could you publish it on docker hub please?

mhmh… i guess no sharing. thanks :slight_smile:

@imapirate i found this after searching github https://github.com/ianneub/docker-erpnext or this https://hub.docker.com/r/davidgu/erpnext/