OMV Scheduled Task for php script running on Nginx in Docker Container

  • What's the correct way to run a recurring task ?


    Previously on OMV 4 with the Nginx plugin, I simply added a OMV Scheduled Task with the 'command' pointing to the php file.


    Now on OMV 5, Nginx is running in a Docker Container.


    Do I use the same Scheduled Task method ?


    How do I determine the correct path to add for the Command ?

  • You could either add cron to the docker container via a container mod.


    Or you could run it via schedule jobs in omv. With this method you need pass the command with docker exec. For example create a scheduled job as root: docker exec sudo -u abc php /config/www/myscript.php

  • You could either add cron to the docker container via a container mod.


    Or you could run it via schedule jobs in omv. With this method you need pass the command with docker exec. For example create a scheduled job as root: docker exec sudo -u abc php /config/www/myscript.php



    set the Command in the OMV Scheduled Tasks :


    Code
    docker exec sudo -u root php /config/www/www/EXDdata/exdgo.php

    Got this error :

    Code
    Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C.UTF-8; export SHELL=/bin/sh; sudo --shell --non-interactive --user=root -- docker exec sudo -u root php /config/www/www/EXDdata/exdgo.php 2>&1' with exit code '1': Error: No such container: sudo
  • Oh sorry:

    docker exec nginx sudo -u root php /config/www/www/EXDdata/exdgo.php

    still results in an error :


    Code
    Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C.UTF-8; export SHELL=/bin/sh; sudo --shell --non-interactive --user=root -- docker exec nginx sudo -u root php /config/www/www/EXDdata/exdgo.php 2>&1' with exit code '126': OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"sudo\": executable file not found in $PATH": unknown
  • Should the php file be run as root?

    i have no idea ( subject unknown to me )


    I did try changing 'root' to 'pi' and the message was simply 'error occurred' and the details show :

    Code
    Error #0:
    OMV\ExecException: Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C.UTF-8; export SHELL=/bin/sh; sudo --shell --non-interactive --user=pi -- docker exec nginx sudo -u pi php /config/www/www/EXDdata/exdgo.php 2>&1' with exit code '1': Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/nginx/json: dial unix /var/run/docker.sock: connect: permission denied in /usr/share/openmediavault/engined/rpc/cron.inc:177
    Stack trace:
    #0 /usr/share/php/openmediavault/rpc/serviceabstract.inc(588): Engined\Rpc\Cron->Engined\Rpc\{closure}('/tmp/bgstatuszG...', '/tmp/bgoutputz4...')
    #1 /usr/share/openmediavault/engined/rpc/cron.inc(181): OMV\Rpc\ServiceAbstract->execBgProc(Object(Closure))
    #2 [internal function]: Engined\Rpc\Cron->execute(Array, Array)
    #3 /usr/share/php/openmediavault/rpc/serviceabstract.inc(123): call_user_func_array(Array, Array)
    #4 /usr/share/php/openmediavault/rpc/rpc.inc(86): OMV\Rpc\ServiceAbstract->callMethod('execute', Array, Array)
    #5 /usr/sbin/omv-engined(537): OMV\Rpc\Rpc::call('Cron', 'execute', Array, Array, 1)
    #6 {main}
  • I have progress :


    tried a few different layouts of that line in the Putty CLI and eventually got this to run the file.


    Code
    sudo docker exec -u root nginx php /config/www/EXDdata/exdgo.php

    seems like the '/config' already points to the first 'www' so only needed the second 'www'


    Am testing in the OMV Scheduled Tasks now

  • try docker exec nginx php /config/www/EXDdata/exdgo.php in scheduled tasks

    both of these options work. I assume that your suggestion ( the second line ) is more secure or stable.


    Code
    sudo docker exec -u root nginx php /config/www/EXDdata/exdgo.php
    
    docker exec nginx php /config/www/EXDdata/exdgo.php


    I am guessing that the OMV Scheduled Tasks are automatically run 'sudo' and that use 'root' is not required in the command as the Scheduled Task dialog already contains the 'root' as the user


    Thank You sincerely for your assistance Morlan. I would not have got this working without your input and guidance. Much appreciated.

  • DaveOB

    Hat das Label gelöst hinzugefügt.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!