subuk / vmango

Your own personal IaaS cloud
https://vmango.org
MIT License
329 stars 55 forks source link

vm_created subscription not working #59

Closed captainwasabi closed 4 years ago

captainwasabi commented 4 years ago

or, at least, I am not seeing any output in the /tmp/sub_output.txt file

I an using the sample script. I put it in /etc and gave the full path in the configuration.

running the script from the command line gives the output that I would expect.

subuk commented 4 years ago

Hi!

Please show configuration file and vmango log, you can get it with journalctl -u vmango

captainwasabi commented 4 years ago

relevant part of log (last 6 lines) --

Jan 17 04:04:48 KONG systemd[1]: Started Virtual Machine Manager.
Jan 17 04:04:48 KONG vmango[21218]: 4:04AM INF using configuration file filename=/etc/vmango.conf
Jan 17 04:04:48 KONG vmango[21218]: 4:04AM INF staring server addr=:8088
Jan 17 04:04:57 KONG vmango[21218]: 4:04AM DBG establishing new connection component=libvirt-connection-pool
Jan 17 04:05:43 KONG vmango[21218]: 4:05AM INF running script component=compute-event-broker event=vm_created script="/etc/ssg-subscribe-script.sh $VMANGO_VM_ID $VMANGO_VM_VOLUME_0_PATH > /tmp/sub_output.txt"
Jan 17 04:30:28 KONG vmango[21218]: 4:30AM INF running script component=compute-event-broker event=vm_created script="/etc/ssg-subscribe-script.sh $VMANGO_VM_ID $VMANGO_VM_VOLUME_0_PATH > /tmp/sub_output.txt"

/etc/vmango.conf

key_file = "/var/lib/vmango/authorized_keys"
libvirt_uri = "qemu:///system"
libvirt_config_drive_pool = "isos"
libvirt_config_drive_suffix = "_config.iso"

# Config drive write format, nocloud or openstack, default=nocloud
# libvirt_config_drive_write_format = "nocloud"

bridges = ["br0"]

web {
    debug = false
    listen = ":8088"
    session_secret = "lafsdaashdhklasdfklasdfjk"

    # Uncomment to set admin / admin password or generate new hash with `vmango genpw`
    user "admin" {
         email = "ssgadmin@ssg.lan"
         hashed_password = "$2a$10$igHQGROHntvl05AztpfMeONSBDUsEbZHxayc5DOPTKIFX50WrHURS"
    }
}

image "/vmango/images/c7base1907.qcow2" {
    os_name = "Centos"
    os_version = "7"
    os_arch = "x86_64"
    protected = true
}

#image "/var/lib/libvirt/images/ubuntu-18.04-minimal-cloudimg-amd64.img" {
#    os_name = "Ubuntu"
#    os_version = "18.04"
#    os_arch = "x86_64"
#    protected = true
#}

# Run script when new vm created
subscribe "vm_created" {
    script = "/etc/ssg-subscribe-script.sh $VMANGO_VM_ID $VMANGO_VM_VOLUME_0_PATH > /tmp/sub_output.txt"
    # Remove vm on script failure
    # mandatory = true
}
subuk commented 4 years ago

Log looks like everything is okay, maybe script prints to stderr? Try to use sample script or redirect all output to log file with &>:

script = "/etc/ssg-subscribe-script.sh $VMANGO_VM_ID $VMANGO_VM_VOLUME_0_PATH &> /tmp/sub_output.txt"
captainwasabi commented 4 years ago

I am using the sample script (I just used a different name).

Changing to &> didn't change anything.

Setting selinux to Permissive didn't help either

I tried echoing straight to the log file from inside the script, doesn't work from vmango, if I run the script by hand it does work.

subuk commented 4 years ago

Ah, vmango uses private tmp: https://github.com/subuk/vmango/blob/master/vmango.service#L12 So look for directory named /tmp/system-private-XXX-vmango.service-XXX/tmp/, file will be there.

subuk commented 4 years ago

You can override unit configuration if necessary https://unix.stackexchange.com/questions/398540/how-to-override-systemd-unit-file-settings

captainwasabi commented 4 years ago

sorry, it took me a bit to circle back around to look at this. Logfile was there.

virt-customize won't run on the image (I think because the image is owned by qemu with perms 600 and vmango is running as vmango)

However, I think I can do what I need to do with Userdata cloud-config

subuk commented 4 years ago

Hooks run from vmango user, if you allow this user to use sudo without password and run virt-customize with sudo, it will work, but yes, cloud-init is a more simple way to customize image.