R
Railway12mo ago
Ayush

Docker Service CRON Restart?

Hi guys, i have a single docker service running. I'd like to restart this service periodically via the Railway CRON functionality. Is this achivable? I am not too sure how to get my container_id
0 0 * * * docker restart <container_name_or_id>
0 0 * * * docker restart <container_name_or_id>
32 Replies
Percy
Percy12mo ago
Project ID: N/A
Ayush
Ayush12mo ago
N/A
Adam
Adam12mo ago
Unfortunately that’s not what Railway’s cron jobs are built for. What you can do though is set up a function in your code that quits your program according to a cron schedule and set your service to restart after quitting in Railway settings
Brody
Brody12mo ago
I've made a template for the exact functionality you would like, but it's not quite ready for public release, would you like me to share it when it's ready?
Ayush
Ayush12mo ago
@Brody that would be awesome thank you very much!
Brody
Brody12mo ago
so just to be clear, you just wanna restart your service on a cron schedule? just the same as clicking the 3 dot menu on the deployment and clicking restart?
Ayush
Ayush12mo ago
@Brody Correct
Brody
Brody12mo ago
gotcha, i just need a good template icon at this point lol I'm not joking, I have no idea what to use as the icon, got any ideas?
Ayush
Ayush12mo ago
so what exactly is the template? is it generic template that will restart any service/project? Or only certain types i.e. docker, node etc? maybe like an hour glass figure?
Brody
Brody12mo ago
it can restart any railway service, doesnt matter what the service is
Ayush
Ayush12mo ago
i kinda like the hour glass figure but idk?
Brody
Brody12mo ago
ill see what i come up with, thanks!
kingoiscool
kingoiscool12mo ago
@Brody I am also interested - was looking for this exact functionality a few weeks ago
Brody
Brody12mo ago
ill keep you both posted
Solution
Brody
Brody12mo ago
Ayush
Ayush12mo ago
Amazing thank you! Will give it a shot
Brody
Brody12mo ago
let me know if there are any difficulties
Ayush
Ayush12mo ago
just set it up now on my project. I have a schedule to restart my service at 12am AEST (roughly 7 hours from now). Will let you know how it goes
Brody
Brody12mo ago
awesome, how easy was the setup?
Ayush
Ayush12mo ago
Very easy but i had no idea bookmarlets was a thing lol 😂
Brody
Brody12mo ago
also, I don't know if I mentioned it in the readme, but the services cron schedule runs on UTC time
Ayush
Ayush12mo ago
oh gotcha makes sense. Will cater for that
Brody
Brody12mo ago
even railways native cron is utc you can just edit the cron expression in the variable and let the service redeploy
Ayush
Ayush12mo ago
sweet thanks fixed it up now, 0 12 * * * should be 12am AEST
Brody
Brody12mo ago
possibly, I don't actually know how to read a cron expression lol
Ayush
Ayush12mo ago
neither lol, im relying on chat gpt 😄
Brody
Brody12mo ago
but you'll get an error message in the deployment logs if the cron expression is invalid
Brody
Brody12mo ago
that's a calendar? did someone ping me?
Ayush
Ayush12mo ago
@Brody looks to be working!
Ayush
Ayush12mo ago
Thanks heaps for that template
Brody
Brody12mo ago
no problem, and if you run into any issues, let me know