mirror of
https://github.com/eliasstepanik/ark-ac-server-tools.git
synced 2026-01-27 16:58:27 +00:00
Add support for adding and removing cron jobs
This commit is contained in:
parent
4eeeebeb8e
commit
eb72148b35
@ -238,6 +238,37 @@ instances.
|
|||||||
`status`::
|
`status`::
|
||||||
Prints the status of the ARK server
|
Prints the status of the ARK server
|
||||||
|
|
||||||
|
`install-cronjob <command>`::
|
||||||
|
Installs a cron job that executes the specified command.
|
||||||
|
This accepts any of the options the specified command accepts,
|
||||||
|
as well as the following options. In order to specify an
|
||||||
|
argument to the command (e.g. to the `broadcast` command),
|
||||||
|
use the `--arg=<arg>` option.
|
||||||
|
|
||||||
|
`--daily`;;
|
||||||
|
The command should be executed daily
|
||||||
|
|
||||||
|
`--hourly`;;
|
||||||
|
The command should be executed hourly
|
||||||
|
|
||||||
|
`--hour=<hour>`;;
|
||||||
|
Specifies one or more hours when the command should execute.
|
||||||
|
This is the hour field of the cron job.
|
||||||
|
|
||||||
|
`--minute=<minute>`;;
|
||||||
|
Specifies one or more minutes of the hour when the command
|
||||||
|
should execute. This is the minute field of the cron job.
|
||||||
|
|
||||||
|
`--enable-output`;;
|
||||||
|
Enables the output from the command - the cron daemon usually
|
||||||
|
emails this to the user specified in the cron configuration
|
||||||
|
|
||||||
|
`--arg=<arg>`;;
|
||||||
|
Specifies an argument to pass to the command
|
||||||
|
|
||||||
|
`remove-cronjob <command>`::
|
||||||
|
Removes a cron job previously installed by `install-cronjob`
|
||||||
|
|
||||||
Configuration files
|
Configuration files
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
@ -1561,6 +1561,64 @@ doBackup(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Install a cron job to execute a particular command
|
||||||
|
#
|
||||||
|
doInstallCronJob(){
|
||||||
|
hour='*'
|
||||||
|
minute='0'
|
||||||
|
cmdopts="${arkCronExtraOpts}"
|
||||||
|
cmdargs=""
|
||||||
|
output=">/dev/null 2>&1"
|
||||||
|
command="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
for opt in "$@"; do
|
||||||
|
case "$opt" in
|
||||||
|
--daily)
|
||||||
|
;;
|
||||||
|
--hourly)
|
||||||
|
hour='*'
|
||||||
|
;;
|
||||||
|
--hour=*)
|
||||||
|
hour="${opt#--hour=}"
|
||||||
|
;;
|
||||||
|
--minute=*)
|
||||||
|
minute="${opt#--minute=}"
|
||||||
|
;;
|
||||||
|
--enable-output)
|
||||||
|
output=
|
||||||
|
;;
|
||||||
|
--arg=*)
|
||||||
|
cmdargs="${cmdargs} $(printf "%q" "${opt#--opt=}")"
|
||||||
|
;;
|
||||||
|
--*)
|
||||||
|
cmdopts="${cmdopts} $(printf "%q" "${opt}")"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
cmdargs="${args} $(printf "%q" "${opt}")"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
cronjob="${minute} ${hour} * * * arkmanager --cronjob ${command} @${instance} ${cmdopts} --args ${cmdargs} -- ${output}"
|
||||||
|
|
||||||
|
(crontab -l | \
|
||||||
|
sed -e "/ [*] [*] [*] arkmanager --cronjob ${command} @${instance} /d";
|
||||||
|
echo "${cronjob}" ) | \
|
||||||
|
crontab -
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Removes an installed cron job
|
||||||
|
#
|
||||||
|
doRemoveCronJob(){
|
||||||
|
command="$1"
|
||||||
|
|
||||||
|
crontab -l | \
|
||||||
|
sed -e "/ [*] [*] [*] arkmanager --cronjob ${command} @${instance} /d" | \
|
||||||
|
crontab -
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Print the status of the server (running? online? version?)
|
# Print the status of the server (running? online? version?)
|
||||||
@ -1697,6 +1755,8 @@ showUsage() {
|
|||||||
echo "installmod <modid> Installs a mod from the Steam workshop"
|
echo "installmod <modid> Installs a mod from the Steam workshop"
|
||||||
echo "uninstallmod <modid> Removes the mod from the Mods directory"
|
echo "uninstallmod <modid> Removes the mod from the Mods directory"
|
||||||
echo "reinstallmod <modid> Removes and re-installs a mod in the Mods directory"
|
echo "reinstallmod <modid> Removes and re-installs a mod in the Mods directory"
|
||||||
|
echo "install-cronjob <cmd> Adds a cron job using the specified command"
|
||||||
|
echo "remove-cronjob <cmd> Removes a cron job that used the specified command"
|
||||||
echo "restart Stops the server and then starts it"
|
echo "restart Stops the server and then starts it"
|
||||||
echo "run Runs the server without daemonizing"
|
echo "run Runs the server without daemonizing"
|
||||||
echo "start Starts the server"
|
echo "start Starts the server"
|
||||||
@ -1746,6 +1806,10 @@ while true; do
|
|||||||
progressDisplayType=spinner
|
progressDisplayType=spinner
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
|
--cronjob)
|
||||||
|
inCronJob=true
|
||||||
|
continue
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# get the number of arguments for commands that take arguments
|
# get the number of arguments for commands that take arguments
|
||||||
@ -1756,6 +1820,8 @@ while true; do
|
|||||||
broadcast) nrarg=1; ;;
|
broadcast) nrarg=1; ;;
|
||||||
rconcmd) nrarg=1; ;;
|
rconcmd) nrarg=1; ;;
|
||||||
useconfig) nrarg=1; ;;
|
useconfig) nrarg=1; ;;
|
||||||
|
install-cronjob) nrarg=1; ;;
|
||||||
|
remove-cronjob) nrarg=1; ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Enumerate the options and arguments
|
# Enumerate the options and arguments
|
||||||
@ -1912,6 +1978,12 @@ while true; do
|
|||||||
status)
|
status)
|
||||||
printStatus
|
printStatus
|
||||||
;;
|
;;
|
||||||
|
install-cronjob)
|
||||||
|
doInstallCronJob "${args[@]}" "${options[@]}"
|
||||||
|
;;
|
||||||
|
remove-cronjob)
|
||||||
|
doRemoveCronJob "${args[@]}"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo -n "arkmanager v${arkstVersion}: unknown command '$command' specified"
|
echo -n "arkmanager v${arkstVersion}: unknown command '$command' specified"
|
||||||
showUsage
|
showUsage
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user