Sebastix / crypto-dca

Tool for automatically buying and withdrawing multiple assets on Kraken.
MIT License
3 stars 0 forks source link

Cron does not start Docker / crypto-dca #9

Closed Nebukadnezzar1 closed 3 years ago

Nebukadnezzar1 commented 3 years ago

Experienced issue: The command * * * * * $(command -v docker) docker run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA won't start. This is tested within the files

The log E-Mail always prints :

unknown flag: --rm
See 'docker --help'.

Usage:  docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
     --config string      Location of client config files (default "/root/.docker")
...

If I run the command manually (without cron), it works like a charm (docker run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA). Same applies for docker run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest balance👍

My System: I'm running on a Raspberry Pi 4 with ubuntu OS 20.04.3 LTS 64bit. Docker itself was installed natively (sudo apt install docker.io) Docker compose was set up using Python3-pip (you know, the aarch64 architecture issues with docker...)

Output of docker version:

Client:
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.8
 Git commit:        20.10.7-0ubuntu1~20.04.2
 Built:             Fri Oct  1 14:05:40 2021
 OS/Arch:           linux/arm64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.8
  Git commit:       20.10.7-0ubuntu1~20.04.2
  Built:            Fri Oct  1 03:27:17 2021
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.5.2-0ubuntu1~20.04.3
  GitCommit:        
 runc:
  Version:          1.0.0~rc95-0ubuntu1~20.04.2
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit:     

Output of docker info:

Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 3
  Running: 2
  Paused: 0
  Stopped: 1
 Images: 3
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-1044-raspi
 Operating System: Ubuntu 20.04.3 LTS
 OSType: linux
 Architecture: aarch64
 CPUs: 4
 Total Memory: 1.805GiB
 Name: ubuntu
 ID: JFJA:TP4G:DR7E:2ZRU:A4SL:KOQY:V2CG:5RQP:B2E4:VT4T:ZYWS:TFHO
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory TCP limit support
WARNING: No oom kill disable support

Output of docker image inspect [imageID]:

[
    {
        "Id": "sha256:31f6111bddfcb06247fd5f8281b11f992826b088e557829c1673b2a440384bc8",
        "RepoTags": [
            "ghcr.io/sebastix/crypto-dca:latest"
        ],
        "RepoDigests": [
            "ghcr.io/sebastix/crypto-dca@sha256:0af2b744cba7a8a8749ea01cadcdc468dee5f144a0adbc9e2bc6afa36409e7ff"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2021-08-17T19:38:45.819153753Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
...

Output of sudo crontab -e:

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
#
# Bitcoin-dca by Sebastix
MAILTO="my@mail.com"
* * * * * $(command -v docker) docker run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA
#

Aside from the issue: Great work by the both of you (Jorijn and Sebastix)! I love the idea to set up & host my own crypto-dca bot. #Kudos!

Nebukadnezzar1 commented 3 years ago

Solution: Since Sebastix's commands are slightly different to Jorijn, I missed one important detail. For the cron, I have to reduce my command by -it and the second docker statement.

Working command: * * * * $(command -v docker) run --rm --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA --yes

The appended -yes will automatically execute the purchase without asking for confirmation.

Kudos to @MarkoE for helping me to solve my problem on Stackoverflow - LINK

Sebastix commented 3 years ago

@Nebukadnezzar1 Missed this issue, but nice to read you've found the solution! Thanks for the compliment. You don't need the docker -it parameter in a cron command because you can't interact (providing input) with a cronjob. I'll close the comment.