How can I programmatically change the system's status?
There are two existing console commands you can use, ./craft on and ./craft off (on and off).
If you want/need to implement your own, take a look at the commit.