Search code examples
cronttylibvirt

virt-install script in crontab how to control tty


I have a script that creates a virtual machine using virt-install. This script uses a kickstart file for unattended installation. It works perfectly fine when triggered through shell but its throws the following error when triggered through crontab:

error: Cannot run interactive console without a controlling TTY

The VM creation process continues at the backend but in my script it doesn't wait for the virt-install to complete and moves on to the next commands. I wanted my script to wait for the virt-install command to complete its job and then move to the next command. Is there any way i can either get a controll on TTY or make my script to wait for virt-install to complete?

Edit

Here is the virt-install command that my script executes (in case it helps you figuring out the issue):

virt-install --connect=qemu:///system \

--network=bridge:$BRIDGE \

$nic2 \

--initrd-inject=$tmp_ks_file \

--controller type=scsi,model=virtio-scsi \

--extra-args="ks=file:/$(basename $tmp_ks_file) console=tty0 console=ttyS0,115200" \

--name=$img_name \

--disk $libvirt_dir/$img_name.img,size=$disk \

--ram $mem \

--vcpus=2 \

--check-cpu \

--accelerate \

--hvm \

--location=$tree \

--nographics

Thanks in advance,

Kashif


Solution

  • I finally able to cater this issue through two steps:

    1. First of all remove the 'console' related configurations from the virt-install command. See extra-args in above command.

    2. Put some logic to wait for virt-install to complete. I did add shutdown in the post install section of kickstart file so that VM shutoff after it is done installing all the packages. Then in my script i actually 'waited' for VM to go to shutdown state before moving to the next command.

    This way I am able to run my script in crontab. It also worked with jenkins too.

    Hope this helps someone facing the same issue.