Updated dockerfile support
diff --git a/dockerfile b/dockerfile
index 3565266..a313f58 100644
--- a/dockerfile
+++ b/dockerfile
@@ -5,15 +5,14 @@
ENV container docker
ENV DEBIAN_FRONTEND=noninteractive
-# Update apt and install required packages including gnupg
+# Update apt and install required packages including systemd, ansible, etc.
RUN apt-get update && \
apt-get install -y gnupg curl systemd ansible sudo git && \
- # Add Bazel's public key (using gpg --dearmor so it can be placed in trusted.gpg.d)
+ # Add Bazel's public key
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/bazel.gpg && \
- apt-get clean && \
- rm -rf /var/lib/apt/lists/*
+ apt-get clean && rm -rf /var/lib/apt/lists/*
-# Set up passwordless sudo (container runs as root so this is just in case)
+# Set up passwordless sudo (container runs as root)
RUN echo "root ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/99_nopasswd && \
chmod 0440 /etc/sudoers.d/99_nopasswd
@@ -21,11 +20,21 @@
COPY . /opt/resilientdb-ansible
WORKDIR /opt/resilientdb-ansible
-# Run the ansible playbook non-interactively (no need for -K since we run as root)
+# Run the ansible playbook non-interactively (passwordless sudo)
RUN ansible-playbook site.yml -i inventories/production/hosts --tags all -e "bazel_jobs=1"
-# Expose ports: 80 for Nginx, 18000 for Crow, 8000 for GraphQL
+# Copy the startup script and unit file into the container
+COPY startup.sh /opt/resilientdb-ansible/startup.sh
+RUN chmod +x /opt/resilientdb-ansible/startup.sh
+
+# Copy the startup unit file and enable it
+COPY startup-services.service /etc/systemd/system/startup-services.service
+
+# Enable the startup service (so that it runs on boot)
+RUN systemctl enable startup-services.service || true
+
+# Expose required ports
EXPOSE 80 18000 8000
-# Use systemd as the container's init system
-CMD ["/sbin/init"]
\ No newline at end of file
+# Start systemd as PID1
+CMD ["/sbin/init"]
diff --git a/roles/crow/handlers/main.yml b/roles/crow/handlers/main.yml
index 405153b..a742de3 100644
--- a/roles/crow/handlers/main.yml
+++ b/roles/crow/handlers/main.yml
@@ -1,10 +1,13 @@
---
+- name: reload systemd
+ systemd:
+ daemon_reload: yes
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
+
- name: restart crow
systemd:
name: crow-http
state: restarted
- daemon_reload: yes
-
-- name: reload systemd
- systemd:
- daemon_reload: yes
\ No newline at end of file
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
diff --git a/roles/crow/tasks/service.yml b/roles/crow/tasks/service.yml
index d224e75..5f6c507 100644
--- a/roles/crow/tasks/service.yml
+++ b/roles/crow/tasks/service.yml
@@ -1,5 +1,5 @@
---
-- name: Create systemd service
+- name: Create systemd service for Crow HTTP Server
template:
src: crow_service.service.j2
dest: /etc/systemd/system/crow-http.service
@@ -8,8 +8,10 @@
- reload systemd
- restart crow
-- name: Enable and restart service
+- name: Enable and restart Crow HTTP service
systemd:
name: crow-http
state: restarted
- enabled: yes
\ No newline at end of file
+ enabled: yes
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
\ No newline at end of file
diff --git a/roles/graphql/handlers/main.yml b/roles/graphql/handlers/main.yml
index 62e93ed..2848f37 100644
--- a/roles/graphql/handlers/main.yml
+++ b/roles/graphql/handlers/main.yml
@@ -2,8 +2,12 @@
- name: reload systemd
systemd:
daemon_reload: yes
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
- name: restart graphql
systemd:
name: graphql
state: restarted
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
diff --git a/roles/graphql/tasks/service.yml b/roles/graphql/tasks/service.yml
index f1322e4..401aabc 100644
--- a/roles/graphql/tasks/service.yml
+++ b/roles/graphql/tasks/service.yml
@@ -1,5 +1,5 @@
---
-- name: Create systemd service
+- name: Create systemd service for GraphQL
template:
src: graphql_service.service.j2
dest: /etc/systemd/system/graphql.service
@@ -8,8 +8,10 @@
- reload systemd
- restart graphql
-- name: Enable and restart service
+- name: Enable and restart GraphQL service
systemd:
name: graphql
state: restarted
- enabled: yes
\ No newline at end of file
+ enabled: yes
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
diff --git a/roles/nginx/handlers/main.yml b/roles/nginx/handlers/main.yml
index ac1df2b..6ac825c 100644
--- a/roles/nginx/handlers/main.yml
+++ b/roles/nginx/handlers/main.yml
@@ -3,8 +3,12 @@
systemd:
name: nginx
state: reloaded
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
- name: restart nginx
systemd:
name: nginx
- state: restarted
\ No newline at end of file
+ state: restarted
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
diff --git a/roles/nginx/tasks/configure.yml b/roles/nginx/tasks/configure.yml
index 45086b6..1bf1854 100644
--- a/roles/nginx/tasks/configure.yml
+++ b/roles/nginx/tasks/configure.yml
@@ -11,7 +11,7 @@
dest: /etc/nginx/sites-available/resilientdb.conf
notify: reload nginx
-- name: Enable site
+- name: Enable Nginx site
file:
src: /etc/nginx/sites-available/resilientdb.conf
dest: /etc/nginx/sites-enabled/resilientdb.conf
diff --git a/roles/resilientdb/handlers/main.yml b/roles/resilientdb/handlers/main.yml
index 7fc7e9e..f998110 100644
--- a/roles/resilientdb/handlers/main.yml
+++ b/roles/resilientdb/handlers/main.yml
@@ -7,4 +7,5 @@
- name: reload systemd
systemd:
- daemon_reload: yes
\ No newline at end of file
+ daemon_reload: yes
+ ignore_errors: yes
\ No newline at end of file
diff --git a/roles/resilientdb/tasks/dependencies.yml b/roles/resilientdb/tasks/dependencies.yml
index 4d1b1e4..511ac5d 100644
--- a/roles/resilientdb/tasks/dependencies.yml
+++ b/roles/resilientdb/tasks/dependencies.yml
@@ -9,9 +9,8 @@
update_cache: yes
cache_valid_time: 3600
-- name: Install Bazel with downgrade allowance
+- name: Install Bazel
apt:
name: "bazel={{ bazel_version }}"
state: present
- allow_downgrades: yes
force: yes
\ No newline at end of file
diff --git a/roles/resilientdb/tasks/restart_node.yml b/roles/resilientdb/tasks/restart_node.yml
index 0315419..e829aef 100644
--- a/roles/resilientdb/tasks/restart_node.yml
+++ b/roles/resilientdb/tasks/restart_node.yml
@@ -4,6 +4,8 @@
name: "resilientdb-kv@{{ item }}"
state: restarted
enabled: yes
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
- name: Pause for 5 seconds after restarting node instance {{ item }}
pause:
diff --git a/roles/resilientdb/tasks/service.yml b/roles/resilientdb/tasks/service.yml
index dff7efb..8ccfe58 100644
--- a/roles/resilientdb/tasks/service.yml
+++ b/roles/resilientdb/tasks/service.yml
@@ -58,6 +58,8 @@
systemd:
daemon_reload: yes
changed_when: false
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
- name: Restart ResilientDB KV Server nodes sequentially
include_tasks: restart_node.yml
@@ -68,9 +70,13 @@
- "4"
loop_control:
loop_var: item
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
- name: Restart ResilientDB KV Client node
systemd:
name: resilientdb-client
state: restarted
- enabled: yes
\ No newline at end of file
+ enabled: yes
+ when: ansible_service_mgr == "systemd"
+ ignore_errors: yes
diff --git a/startup-services.service b/startup-services.service
new file mode 100644
index 0000000..d1c24b2
--- /dev/null
+++ b/startup-services.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Start custom services after boot
+After=network.target
+
+[Service]
+Type=oneshot
+ExecStart=/opt/resilientdb-ansible/startup.sh
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
diff --git a/startup.sh b/startup.sh
new file mode 100644
index 0000000..6b66117
--- /dev/null
+++ b/startup.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+# Wait a few seconds to let systemd fully boot
+sleep 5
+
+echo "Reloading systemd daemon..."
+systemctl daemon-reload
+
+echo "Enabling and starting all custom services..."
+systemctl enable nginx && systemctl start nginx
+systemctl enable crow-http && systemctl start crow-http
+systemctl enable graphql && systemctl start graphql
+systemctl enable resilientdb-client && systemctl start resilientdb-client
+systemctl enable resilientdb-kv@1 && systemctl start resilientdb-kv@1
+systemctl enable resilientdb-kv@2 && systemctl start resilientdb-kv@2
+systemctl enable resilientdb-kv@3 && systemctl start resilientdb-kv@3
+systemctl enable resilientdb-kv@4 && systemctl start resilientdb-kv@4
+
+echo "Custom services started."