在GKE中使用crond运行Selenium作业

时间:2017-08-08 04:10:30

标签: docker kubernetes google-kubernetes-engine

我的泊坞窗文件的快照如下:

#Assume i have ubuntu, selenium and chrome driver in the image

ADD crontab /etc/cron.d/simple-cron
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/simple-cron

# Add shell script and grant execution rights

RUN wget myjava.jar [From some central repository]
RUN chmod +x /myjava.jar


ADD script.sh /script.sh
RUN chmod 777 /script.sh

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/simple-cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log


ADD run.sh /run.sh
RUN chmod +x /run.sh
CMD ["/run.sh"]



Crontab:
* * * * * root /script.sh

script.sh:
export DISPLAY=:99
cd /
/usr/bin/java -jar myjava.jar >> /var/log/cron.log 2>&1

run.sh:
#!/bin/bash
Xvfb :99 -screen 0 1024x768x16 &
cron && tail -f /var/log/cron.log

问题:我在GKE容器中部署了上面的图像。

按照上述配置,我的cron作业应该每1分钟运行一次。但由于某些原因,我没有看到调用cron工作。

我在这里遗漏了什么?这可能是由于后台显示缓冲区" xvfb"进程和cron进程在同一个pod中运行?

当我在本地docker容器中下载图像时,我看到cron正常运行,我没有看到任何问题。只有当图像由于某种原因部署到GKE时,cron才会执行script.sh

我在我的GKE容器上安装了strace,什么时候执行strace cron,我看到以下日志:

/# strace cron
execve("/usr/sbin/cron", ["cron"], [/* 33 vars */]) = 0
brk(NULL)                               = 0xff8000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffa0cec0000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=30704, ...}) = 0
mmap(NULL, 30704, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffa0ceb8000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libpam.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200$\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=55904, ...}) = 0
mmap(NULL, 2150888, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffa0ca8f000
mprotect(0x7ffa0ca9c000, 2093056, PROT_NONE) = 0
mmap(0x7ffa0cc9b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xc000) = 0x7ffa0cc9b000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260Z\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=130224, ...}) = 0
mmap(NULL, 2234080, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffa0c86d000
mprotect(0x7ffa0c88c000, 2093056, PROT_NONE) = 0
mmap(0x7ffa0ca8b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e000) = 0x7ffa0ca8b000
mmap(0x7ffa0ca8d000, 5856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffa0ca8d000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffa0ceb7000
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffa0c4a3000
mprotect(0x7ffa0c663000, 2097152, PROT_NONE) = 0
mmap(0x7ffa0c863000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7ffa0c863000
mmap(0x7ffa0c869000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffa0c869000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libaudit.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0*\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=117288, ...}) = 0
mmap(NULL, 2253352, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffa0c27c000
mprotect(0x7ffa0c298000, 2093056, PROT_NONE) = 0
mmap(0x7ffa0c497000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b000) = 0x7ffa0c497000
mmap(0x7ffa0c499000, 37416, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffa0c499000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\r\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14608, ...}) = 0
mmap(NULL, 2109680, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffa0c078000
mprotect(0x7ffa0c07b000, 2093056, PROT_NONE) = 0
mmap(0x7ffa0c27a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7ffa0c27a000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libpcre.so.3", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\25\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=456632, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffa0ceb6000
mmap(NULL, 2552072, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffa0be08000
mprotect(0x7ffa0be76000, 2097152, PROT_NONE) = 0
mmap(0x7ffa0c076000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6e000) = 0x7ffa0c076000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260`\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=138696, ...}) = 0
mmap(NULL, 2212904, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffa0bbeb000
mprotect(0x7ffa0bc03000, 2093056, PROT_NONE) = 0
mmap(0x7ffa0be02000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7ffa0be02000
mmap(0x7ffa0be04000, 13352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffa0be04000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffa0ceb5000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffa0ceb3000
arch_prctl(ARCH_SET_FS, 0x7ffa0ceb3800) = 0
mprotect(0x7ffa0c863000, 16384, PROT_READ) = 0
mprotect(0x7ffa0be02000, 4096, PROT_READ) = 0
mprotect(0x7ffa0c076000, 4096, PROT_READ) = 0
mprotect(0x7ffa0c27a000, 4096, PROT_READ) = 0
mprotect(0x7ffa0c497000, 4096, PROT_READ) = 0
mprotect(0x7ffa0ca8b000, 4096, PROT_READ) = 0
mprotect(0x7ffa0cc9b000, 4096, PROT_READ) = 0
mprotect(0x609000, 4096, PROT_READ)     = 0
mprotect(0x7ffa0cec2000, 4096, PROT_READ) = 0
munmap(0x7ffa0ceb8000, 30704)           = 0
set_tid_address(0x7ffa0ceb3ad0)         = 129
set_robust_list(0x7ffa0ceb3ae0, 24)     = 0
rt_sigaction(SIGRTMIN, {0x7ffa0bbf0b50, [], SA_RESTORER|SA_SIGINFO, 0x7ffa0bbfc390}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7ffa0bbf0be0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7ffa0bbfc390}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
statfs("/sys/fs/selinux", 0x7ffc94589100) = -1 ENOENT (No such file or directory)
statfs("/selinux", 0x7ffc94589100)      = -1 ENOENT (No such file or directory)
brk(NULL)                               = 0xff8000
brk(0x1019000)                          = 0x1019000
open("/proc/filesystems", O_RDONLY)     = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "nodev\tsysfs\nnodev\trootfs\nnodev\tr"..., 1024) = 285
read(3, "", 1024)                       = 0
close(3)                                = 0
rt_sigaction(SIGCHLD, {0x403190, [CHLD], SA_RESTORER|SA_RESTART, 0x7ffa0c4d84b0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGHUP, {0x403170, [HUP], SA_RESTORER|SA_RESTART, 0x7ffa0c4d84b0}, {SIG_DFL, [], 0}, 8) = 0
fcntl(0, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
open("/var/run/crond.pid", O_RDWR|O_CREAT, 0644) = 3
fcntl(3, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
flock(3, LOCK_EX|LOCK_NB)               = 0
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=127, ...}) = 0
fstat(4, {st_mode=S_IFREG|0644, st_size=127, ...}) = 0
read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\1\0\0\0\0"..., 4096) = 127
lseek(4, -71, SEEK_CUR)                 = 56
read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\1\0\0\0\0"..., 4096) = 71
close(4)                                = 0
socket(PF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 4
connect(4, {sa_family=AF_LOCAL, sun_path="/dev/log"}, 110) = -1 ENOENT (No such file or directory)
close(4)                                = 0
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=3, ...}) = 0
lseek(3, 0, SEEK_SET)                   = 0
write(3, "129\n", 4)                    = 4
lseek(3, 0, SEEK_CUR)                   = 4
ftruncate(3, 4)                         = 0
setresuid(-1, 0, -1)                    = 0
stat("/var/spool/cron", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
chdir("/var/spool/cron")                = 0
stat("crontabs", {st_mode=S_IFDIR|S_ISVTX|0730, st_size=4096, ...}) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ffa0ceb3ad0) = 130

1 个答案:

答案 0 :(得分:0)

问题可能是你的cron工作线不正确。你需要像这样添加它。

假设您的脚本完整路径为/root/setup.sh。你的cron入口应该是这样的。

crontab的:

* * * * * /root/script.sh

还尝试提供jar文件myjava.jar的完整路径名并进行测试。

由于