diff --git a/Dockerfile.server b/Dockerfile.server index 24237a53..d88f7fbd 100644 --- a/Dockerfile.server +++ b/Dockerfile.server @@ -28,7 +28,7 @@ RUN cd /opt \ && git clone https://github.com/ToolDAQ/middleman.git \ && cd middleman/ \ && git checkout v3.0 \ - && ./Setup.sh \ + && . Setup.sh \ && make # docs build fails if index.html is not present, which kills the docker build @@ -49,17 +49,17 @@ RUN cd /opt \ RUN sed -e 's/#LoadModule mpm_prefork_module/LoadModule mpm_prefork_module/' -i /etc/httpd/conf.modules.d/00-mpm.conf \ && sed -e '/LoadModule mpm_event_module/ s/^#*/#/' -i /etc/httpd/conf.modules.d/00-mpm.conf -RUN echo "unalias cp" >> /etc/rc.local ;\ +RUN echo 'CP=$(type -t cp)' >> /etc/rc.local ;\ + echo 'if [ ! -z "${CP}" ]; then unalias cp; fi' >> /etc/rc.local ;\ echo "cp -f /web/httpd.conf /etc/httpd/conf/" >> /etc/rc.local ;\ echo "alias cp='cp -i'" >> /etc/rc.local ;\ echo "chmod a+x /web/SetupDatabase.sh" >> /etc/rc.local ;\ echo "chmod a+x /opt/middleman/run_middleman.sh" >> /etc/rc.local ;\ echo "chmod a+x /opt/middleman/Setup.sh" >> /etc/rc.local ;\ - echo "export LD_LIBRARY_PATH=/lib/:/opt/ToolFrameworkCore/lib:/opt/ToolDAQFramework/lib:/opt/boost_1_66_0/install/lib:/opt/zeromq-4.0.7/lib:/opt/libpqxx-6.4.5/install/lib:$LD_LIBRARY_PATH" >> /etc/rc.local ;\ + echo 'export LD_LIBRARY_PATH=/lib/:/opt/ToolFrameworkCore/lib:/opt/ToolDAQFramework/lib:/opt/boost_1_66_0/install/lib:/opt/zeromq-4.0.7/lib:/opt/libpqxx-6.4.5/install/lib:$LD_LIBRARY_PATH' >> /etc/rc.local ;\ echo "cd /web && make clean && make" >> /etc/rc.local ;\ echo "cd /web/cgi-bin && make clean && make" >> /etc/rc.local ;\ echo "/web/SetupDatabase.sh" >> /etc/rc.local ;\ - echo "sudo -u postgres /usr/bin/pg_ctl start -D /var/lib/pgsql/data -s -o \"-p 5432\" -w -t 300;" >> /etc/rc.local;\ echo "/opt/middleman/run_middleman.sh &> /dev/null &" >> /etc/rc.local ;\ echo 'disown $!' >> /etc/rc.local ;\ echo "/web/Win_Mac_translation_server &> /dev/null &" >> /etc/rc.local ;\ diff --git a/README.md b/README.md index 44bbfcb5..390ec205 100755 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ to create docker container with webserver in use: linux: - docker run --name=WebServer -v local_git_clone_path:/web --mount type=tmpfs,dst=/tmp,tmpfs-size=500M --net=host -dt tooldaq/server + docker run --name=WebServer -v local_git_clone_path:/web --mount type=tmpfs,dst=/tmp,tmpfs-size=500M --net=host --cap-add=CAP_AUDIT_WRITE -dt tooldaq/server Windows / MacOS: diff --git a/SetupDatabase.sh b/SetupDatabase.sh index 7c36fbe4..dd2f8e70 100755 --- a/SetupDatabase.sh +++ b/SetupDatabase.sh @@ -1,18 +1,50 @@ #!/bin/bash set +x +systemctl status &>/dev/null +USE_SYSTEMD=$? set -e +if [ ${USE_SYSTEMD} -eq 0 ]; then + echo "running database as systemd unit" +else + echo "running database via pg_ctl" +fi # only take action on first run if [ -f /.DBSetupDone ]; then - exit 0; + + # systemd version for baremetal + if [ ${USESYSTEMD} -eq 0 ]; then + # note no [ ] in following check + if ! systemctl is-active --quiet postgresql; then + sudo systemctl start postgresql + fi + exit 0; + else + # pg_ctl version for containers + if [ `pg_ctl -D /var/lib/pgsql/data status &>/dev/null && echo $?` -ne 0 ]; then + sudo -u postgres /usr/bin/pg_ctl start -D /var/lib/pgsql/data -s -o "-p 5432" -w -t 300 + fi + exit 0; + fi fi export LC_ALL=C echo "Initialising postgresql cluster" cd /var/lib/pgsql/ -#sudo chown -R postgres /var/lib/pgsql -#sudo chown -R postgres /var/run/postgresql -sudo -u postgres /usr/bin/initdb /var/lib/pgsql/data/ +# --waldir=/todo/replication +sudo -u postgres /usr/bin/initdb --data-checksums /var/lib/pgsql/data/ + +# set it up to listen on all network interfaces, rather than (by default) localhost only +echo "listen_addresses = '*'" | sudo -u postgres tee -a /var/lib/pgsql/data/postgresql.conf + echo "Starting postgres server" -sudo -u postgres /usr/bin/pg_ctl start -D /var/lib/pgsql/data -s -o "-p 5432" -w -t 300 +if [ ${USE_SYSTEMD} -eq 0 ]; then + # systemd version + sudo systemctl enable --now postgresql +else + # container version + sudo mkdir -p /var/run/postgresql && sudo chown -R postgres /var/run/postgresql + sudo -u postgres /usr/bin/pg_ctl start -D /var/lib/pgsql/data -s -o "-p 5432" -w -t 300 +fi + echo "creating root database user" sudo -u postgres createuser -s root echo "creating 'daq' database"