Since you don’t want to spend the money on a true NAS we could look at this…
Why does it log out or not work sometimes? The uptime on my iMac is 24 days right now, and the last restart was for an update. The uptime on my NAS is 22 days (and that restart was an update, too). I use my Mac for the server and the NAS for the storage since the CPU in my Mac is a LOT better than in the NAS. Both are hooked up to an UPS, and you seem like you already have one of those.
I have my Mac display set to turn off after 5 minutes, but to never go to sleep. Sometimes for some weird reason (prob my kids on their account but I never tracked it down), it would still go to sleep so I got the app ‘Amphetamine’ and use that all the time now. That’s set to never let my Mac go to sleep as well as the Energy Settings for the Mac, and since I added that it’s never gone to sleep