From 390950df2ef6d5e10e36f35fb0c8f74fff89e010 Mon Sep 17 00:00:00 2001 From: Marcus Ahlfors Date: Mon, 13 Nov 2023 21:27:38 +0200 Subject: [PATCH] Add sudo, supervisorctl to sudoers, create script for regular user to restart odoo --- Dockerfile | 14 ++++++-------- odoo-sudoers | 3 +++ odooctl | 30 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 odoo-sudoers create mode 100755 odooctl diff --git a/Dockerfile b/Dockerfile index 94ead89..dcb287e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ FROM ghcr.io/diploi/odoo16-arm:latest - # This dockerfile is run by diploi image builder, it will have # this template repository as it's base and the actual project # repository will be mounted in the repository folder. @@ -21,7 +20,8 @@ COPY update_odoo_home.sh /etc/profile.d/update_odoo_home.sh #RUN chown odoo /var/lib/odoo/sessions # Update basic packages -RUN apt-get update && apt-get install -y nano supervisor openssh-server git bash wget curl locales libc6 libstdc++6 ca-certificates tar +RUN apt-get update + && apt-get install -y nano supervisor openssh-server git bash wget curl locales libc6 libstdc++6 ca-certificates tar sudo # Install PostgreSQL client #RUN apt-get install -y postgresql-client @@ -41,16 +41,12 @@ RUN mkdir -p /run/sshd /root/.ssh \ # echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && \ # echo "LANG=en_US.UTF-8" > /etc/locale.conf && \ # locale-gen en_US.UTF-8 - + # Gitconfig secrets and credential helper RUN ln -s /etc/diploi-git/gitconfig /etc/gitconfig COPY diploi-credential-helper /usr/local/bin -# Experimental add odoo user -#RUN apt-get update && apt-get -y install sudo -#RUN adduser odoo sudo - -# Fake pod ready +# Fake pod ready: TODO: fix actual probe RUN touch /tmp/pod-ready # Init and run supervisor @@ -60,6 +56,8 @@ COPY odoo-init.py /odoo-init.py COPY runonce.sh /root/runonce.sh COPY runonce-odoo.sh /home/odoo/runonce-odoo.sh RUN chown odoo:odoo /home/odoo/runonce-odoo.sh +COPY odoo-sudoers /etc/sudoers.d/odoo-sudoers +COPY odooctl /usr/local/bin/odooctl # Copy a version of home so we can copy it in the mounted development version RUN tar cvf /root/initial-odoo-home.tar /home/odoo diff --git a/odoo-sudoers b/odoo-sudoers new file mode 100644 index 0000000..9897b7f --- /dev/null +++ b/odoo-sudoers @@ -0,0 +1,3 @@ + +# Allow odoo to run supervisorctl +odoo ALL=(ALL:ALL) NOPASSWD: /usr/bin/supervisorctl \ No newline at end of file diff --git a/odooctl b/odooctl new file mode 100755 index 0000000..66f96f2 --- /dev/null +++ b/odooctl @@ -0,0 +1,30 @@ +#!/bin/bash + +# Show usage information +usage() { + echo "Usage: odooctl {start|stop|restart}" + exit 1 +} + +# Check if the script was called with an argument +if [ $# -eq 0 ]; then + usage +fi + +# Check the argument and perform the corresponding action +case "$1" in + "start") + sudo supervisorctl start odoo + ;; + "stop") + sudo supervisorctl stop odoo + ;; + "restart") + sudo supervisorctl restart odoo + ;; + *) + usage + ;; +esac + +exit 0 \ No newline at end of file