Can't execute hook with the new Hook system // Autorestart VM

Hello,
I have OpenNebula 5.10.1 and I want to restart the VMs in case of a hardware reset or a server crash, and I have a hook created as follow:

ARGUMENTS="$ID"
COMMAND="/usr/bin/env onevm resume"
LCM_STATE=“UNKNOWN”
ON=“yes”
REMOTE=“YES”
RESOURCE=“VM”
STATE=“ACTIVE”

But I get this error:

$ onehook show 0 -e 15
HOOK 0 INFORMATION
ID : 0
NAME : autostart_hook
TYPE : state
LOCK : None

HOOK EXECUTION RECORD
EXECUTION ID : 15
TIMESTAMP : 01/20 17:41:10
COMMAND : /usr/bin/env onevm resume $ID
ARGUMENTS : $ID
EXIT CODE : 127

EXECUTION STDOUT

**EXECUTION STDERR **
/usr/bin/env: onevm: No such file or directory

With a OpenNebula 5.8 everything was working as expected and I can’t figure out what’s wrong.
Thanks for your help

Hello @Marco , didn’t you better want to run hook locally, on the frontend? See:

REMOTE=“NO”

Best regards,
Vlastimil

Hello @Vlastimil_Holer
yes, that makes sense, thank you.
Anyway the problem is not solved and the error has changed:

 HOOK 1 INFORMATION                                                              
ID                : 1                   
NAME              : autostart_hook      
TYPE              : state               
LOCK              : None                

HOOK EXECUTION RECORD                                                           
EXECUTION ID      : 2                   
TIMESTAMP         : 01/21 16:36:10      
COMMAND           : /usr/bin/env onevm resume $ID 
ARGUMENTS         : $ID                 
EXIT CODE         : 255                 

EXECUTION STDOUT                                                                
Command resume requires one parameter to run
## USAGE
resume <range|vmid_list>
        Resumes the execution of the a saved VM
        
        States: STOPPED, SUSPENDED, UNDEPLOYED, POWEROFF, UNKNOWN
        valid options: schedule, weekly, monthly, yearly, hourly, end

## OPTIONS
     --schedule TIME           Schedules this action to be executed afterthe
                               given time. For example: onevm resume 0
                               --schedule "09/23 14:15"
     --weekly days             Repeats the schedule action the days of the week
                               specified, it can be a number between 0,6
                               separated with commas.For example: onevm resume
                               0 --schedule "09/23 14:15" --weekly 0,2,4
     --monthly days            Repeats the schedule action the days of the month
                               specified, it can be a number between 0,31
                               separated with commas.For example: onevm resume
                               0 --schedule "09/23 14:15" --monthly 0,14
     --yearly days             Repeats the schedule action the days of the year
                               specified, it can be a number between 0,365
                               separated with commas.For example: onevm resume
                               0 --schedule "09/23 14:15" --yearly 30,60
     --hourly hour             Repeats the schedule action each hours
                               specified,it can be a number between 0,168
                               separated with commas.For example: onevm resume
                               0 --schedule "09/23 14:15" --hourly 1,5
     --end number|TIME         ----
     -v, --verbose             Verbose mode
     -h, --help                Show this message
     -V, --version             Show version and copyright information
     --user name               User name used to connect to OpenNebula
     --password password       Password to authenticate with OpenNebula
     --endpoint endpoint       URL of OpenNebula xmlrpc frontend

EXECUTION STDERR                                                                

==============================================

$ onehook show 1
HOOK 1 INFORMATION                                                              
ID                : 1                   
NAME              : autostart_hook      
TYPE              : state               
LOCK              : None                

HOOK TEMPLATE                                                                   
ARGUMENTS="$ID"
COMMAND="/usr/bin/env onevm resume"
LCM_STATE="UNKNOWN"
RESOURCE="VM"
STATE="ACTIVE"

Hello @Marco

With new hooks system, there is no $ID, the argument is always $TEMPLATE, so you have to parse it to get the ID of the VM. You can find more information about state hooks here.

Ok @ahuertas, thanks
I will try to work it out.