lxc / python3-lxc

Python 3.x binding for liblxc
https://linuxcontainers.org/lxc
GNU Lesser General Public License v2.1
57 stars 38 forks source link

script fails when run as a cron #12

Closed jjriv closed 5 years ago

jjriv commented 5 years ago

Required information

lxc-start --version: 1.0.11 `lxc-checkconfig Kernel configuration not found at /proc/config.gz; searching... Kernel configuration found at /boot/config-3.10.0-957.10.1.el7.x86_64 --- Namespaces --- Namespaces: enabled Utsname namespace: enabled Ipc namespace: enabled Pid namespace: enabled User namespace: enabled newuidmap is not installed newgidmap is not installed Network namespace: enabled Multiple /dev/pts instances: enabled

--- Control groups --- Cgroup: enabled Cgroup clone_children flag: enabled Cgroup device: enabled Cgroup sched: enabled Cgroup cpu account: enabled Cgroup memory controller: enabled Cgroup cpuset: enabled

--- Misc --- Veth pair device: enabled Macvlan: enabled Vlan: enabled Bridges: enabled Advanced netfilter: enabled CONFIG_NF_NAT_IPV4: enabled CONFIG_NF_NAT_IPV6: enabled CONFIG_IP_NF_TARGET_MASQUERADE: enabled CONFIG_IP6_NF_TARGET_MASQUERADE: enabled CONFIG_NETFILTER_XT_TARGET_CHECKSUM: enabled

--- Checkpoint/Restore --- checkpoint restore: enabled CONFIG_FHANDLE: enabled CONFIG_EVENTFD: enabled CONFIG_EPOLL: enabled CONFIG_UNIX_DIAG: enabled CONFIG_INET_DIAG: enabled CONFIG_PACKET_DIAG: enabled CONFIG_NETLINK_DIAG: enabled File capabilities: enabled `

Note : Before booting a new kernel, you can check its configuration usage : CONFIG=/path/to/config /bin/lxc-checkconfig

Issue description

I have a python script that is using LXC to validate postgresql backups inside a CentOS 7 container. The script runs fine when run from the command line. However, when it runs as a cron it errors out with some cryptic messages:

lxc_container: attach.c: lxc_attach_run_command: 1298 No such file or directory - failed to exec 'runuser'

The commands being run by attach_wait(lxc.attach_run_command...) appear to be running out of order when run inside a cron.

Steps to reproduce

  1. Run the script manually. Success.
  2. Schedule cron job in /etc/cron.d/xyz
  3. Wait for cron job to run... then observe failure

Information to attach

Here is the script I am running: https://github.com/jjriv/Python-Sys-Admin-Scripts/blob/master/postgres-backup-validation

jjriv commented 5 years ago

I have since got this working by replacing the 'runuser' command with 'su -', like so: c.attach_wait(lxc.attach_run_command, ["su", "-", "postgres", "-c", "psql " + dbname + " -t -c 'SELECT create_time FROM mail_queue ORDER BY id DESC LIMIT 1' > " + mediadir + "/" + datefile])

I still don't understand why this works and runuser does not, but i'm ok with that as long as it's working :)

cheers.