R
Railway16mo 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
Percy16mo ago
Project ID: N/A
Ayush
AyushOP16mo ago
N/A
Adam
Adam16mo 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
Brody16mo 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
AyushOP16mo ago
@Brody that would be awesome thank you very much!
Brody
Brody16mo 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
AyushOP16mo ago
@Brody Correct
Brody
Brody16mo 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
AyushOP16mo 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
Brody16mo ago
it can restart any railway service, doesnt matter what the service is
Ayush
AyushOP16mo ago
i kinda like the hour glass figure but idk?
Brody
Brody16mo ago
ill see what i come up with, thanks!
kingoiscool
kingoiscool16mo ago
@Brody I am also interested - was looking for this exact functionality a few weeks ago
Brody
Brody16mo ago
ill keep you both posted
Solution
Brody
Brody16mo ago
Ayush
AyushOP16mo ago
Amazing thank you! Will give it a shot
Brody
Brody16mo ago
let me know if there are any difficulties
Ayush
AyushOP16mo 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
Brody16mo ago
awesome, how easy was the setup?
Ayush
AyushOP16mo ago
Very easy but i had no idea bookmarlets was a thing lol 😂
Brody
Brody16mo ago
also, I don't know if I mentioned it in the readme, but the services cron schedule runs on UTC time
Ayush
AyushOP16mo ago
oh gotcha makes sense. Will cater for that
Brody
Brody16mo ago
even railways native cron is utc you can just edit the cron expression in the variable and let the service redeploy
Ayush
AyushOP16mo ago
sweet thanks fixed it up now, 0 12 * * * should be 12am AEST
Brody
Brody16mo ago
possibly, I don't actually know how to read a cron expression lol
Ayush
AyushOP16mo ago
neither lol, im relying on chat gpt 😄
Brody
Brody16mo ago
but you'll get an error message in the deployment logs if the cron expression is invalid
Brody
Brody16mo ago
that's a calendar? did someone ping me?
Ayush
AyushOP16mo ago
@Brody looks to be working!
Ayush
AyushOP16mo ago
Thanks heaps for that template
Brody
Brody16mo ago
no problem, and if you run into any issues, let me know
Want results from more Discord servers?
Add your server