Skip to content

Commit

Permalink
Issue RotherOSS#51: first stab at running Daemon and Cron in own shell
Browse files Browse the repository at this point in the history
Not really tested yet.
  • Loading branch information
bschmalhofer committed May 28, 2020
1 parent 316e3f0 commit 0ba0fcc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ RUN perl bin/docker/set_permissions.pl
# start the webserver
# start the Cron watchdog
# Tell the webapplication that it runs in a container.
USER otobo
# The entrypoint takes one command: 'web' or 'cron'
ENV OTOBO_RUNS_UNDER_DOCKER 1
ENTRYPOINT ["/opt/otobo/bin/docker/entrypoint.sh"]
ENV OTOBO_USER otobo
ENTRYPOINT ["bin/docker/entrypoint.sh"]
54 changes: 37 additions & 17 deletions bin/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
#!/usr/bin/env bash

# no command line arguments are handled
# root handles 'cron' and defers 'web' to the OTOBO user
if [ $UID -eq 0 ]; then
echo "otobo_user: $OTOBO_USER";
if [ "$1" = "cron" ]; then
# Start the OTOBO Daemon.
# The Daemon will exit immediately when SecureMode = 0.
# But this is OK, as Cron will restart it and it will run when SecureMode = 1.
su -c "./bin/otobo.Daemon.pl start" "$OTOBO_USER"

# Start up OTOBO Daemon and the webserver
# Run a watchdog over the Daemon via Cron
# assume that we are in /opt/otobo
su -c "mkdir -p var/tmp" "$OTOBO_USER"

# assume that we are in /opt/otobo
mkdir -p var/tmp
# set up the cronjobs as they are declared in var/cron
su -c "./bin/Cron.sh start" "$OTOBO_USER"

# set up the cronjobs as they are declared in var/cron
./bin/Cron.sh start
# Run a watchdog over the Daemon via Cron
# run cron in the foreground
exec cron -f
# nothing will be executed beyond that line,
# because exec replaces running process with the new one
fi

# Start the Daemon.
# The Daemon will exit immediately when SecureMode = 0.
# But this is OK, as Cron will restart it and it will run when SecureMode = 1.
./bin/otobo.Daemon.pl start
# everything else is run as otobo
exec su "$OTOBO_USER" "$0" -- "$@"
# nothing will be executed beyond that line,
# because exec replaces running process with the new one
fi

# maintainance jobs
# TODO: decide whether it makes sense to run these jobs on startup
#perl ./bin/otobo.Console.pl Maint::Config::Rebuild
#perl ./bin/otobo.Console.pl Maint::Cache::Delete
echo "The command $1 will be run from user $UID."

# Start the webserver
plackup --server Gazelle -R Kernel,bin/psgi-bin/otobo.psgi --port 5000 bin/psgi-bin/otobo.psgi
if [ "$1" = "web" ]; then
# maintainance jobs
# TODO: decide whether it makes sense to run these jobs on startup
#perl ./bin/otobo.Console.pl Maint::Config::Rebuild
#perl ./bin/otobo.Console.pl Maint::Cache::Delete

# Start the webserver
plackup --server Gazelle -R Kernel,bin/psgi-bin/otobo.psgi --port 5000 bin/psgi-bin/otobo.psgi

else
echo "Unknown option $1. Exiting."
exit -1
fi
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ services:
# use ./Dockerfile for building, image otobo-web
build:
context: .
# give a name to the build image so that the service 'cron' can reuse it
image: otobo_web:latest
depends_on:
- db
restart: always
Expand All @@ -41,6 +43,13 @@ services:
- "5000:5000"
volumes:
- opt_otobo:/opt/otobo
command: web

cron:
image: otobo_web:latest
volumes:
- opt_otobo:/opt/otobo
command: cron

# no volumnes need to be exposed across services
volumes:
Expand Down

0 comments on commit 0ba0fcc

Please sign in to comment.