Automatically restart a resource using a script



Hey guys,

Curious I have a resource that needs to be restarted every 30 minutes roughly, now usually i’d just do this in console ‘restart XXXX’

How can i get a .bat file or something of the like to automatically restart the resource every 30 minutes? I can write .bat files, i am just not sure how to impliment it in as the only way to get that command to work would be through the console, unless i put something in the server.cfg that runs on loop?

Idea would be appreciated!



Why would you need to restart a resource? Restarting resources on a live server is a very bad practice. Try putting whatever the script does inside a loop instead. Mind sharing what resource you have that needs to be restarted?


I’ve seen auto server restart bat scripts. I’d like to add that, however, we’d also need a function to alert players before it happens. Do you know if that’s possible?

Ex: Server restarts every 6 hrs. We want to alert players like this in intervals “Server Restarting in 10 mins!”, “Server Restarting in 5 mins!”, “Server Restarting!”


How is this related to something that restarts a specific resource exactly? As this topic is not about restarting servers.

Sure it’s possible. If you have a schedule just run a resource on the server, that triggers client events to notify them each x minutes, each time decreasing the remaining time before the server restarts. Though if you want to go into more detail on this, create your own topic please :wink:


lol my bad I didn’t read the topic clearly (I was half asleep). Thank you for the info.


els keeps bugging out for SOME people after 20 or so minutes. Restarting the resource els fixes the issues for anyone that was having an issue.

Something within els thats causing it just dont know what yet, this is a band aid fix


In that case I suggest you report this to the developer who made the ELS resource, as this clearly shouldn’t happen in the first place, restarting a resource should never be necessary. However, if you really want to restart it, simply create a resource like this on the server and it should work.

local delay = 1000 * 60 * 30 -- just edit this to your needed delay (30 minutes in this example)
    while true do
        ExecuteCommand("restart <resourcename>")

I haven’t tried this but I assume it would work fine as long as your resource has permission to execute that command.
To give it permissions just add this to your server.cfg file.

add_ace resource.<resource name for the script above> command.restart allow
add_ace resource.<resource name for the script above> command.start allow
add_ace resource.<resource name for the script above> command.stop allow


I might need this for one function only, weirdly, even after a few rewrites to find the bug, my resource (containing a es chat command) only works after i restart the resource during runtime.
For the life in me i can’t figure out why, i tried a ton of things , but the problem persists.
Basicly when i run the command it should read through a a table called back from the server.
but it seems that table returns nil until i restart that resource. The weird part tho, is the event i use to do this, is nearly an exact copy of another event that does a similar thing (serverside) yet it never failed me. So i’m baffled on this one.