#!/bin/bash
# info: Suspending sys cron jobs
# options: user [restart]
#
# The function suspends all user cron jobs.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument defenition
user=$1
restart=$2

# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh


#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '1' "$#" 'user'
validate_format 'user'
is_object_valid 'user' 'USER' "$user"


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Suspendn all jobs
for job in $(search_objects 'cron' 'SUSPENDED' 'no' 'JOB'); do
    $BIN/v_suspend_cron_job $user $job 'no'
done


#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# Restart crond
if [ "$restart" != 'no' ]; then
    $BIN/v_restart_cron "$EVENT"
fi

# Logging
log_event "$OK" "$EVENT"

exit
