add macOS support, and refactor
Added daemon support for MacOS. Used launchd and launchctl, which are analogous to linux's systems and systemctl.
launchd: https://www.manpagez.com/man/5/launchd.plist/, https://www.launchd.info/
launchctl: https://ss64.com/osx/launchctl.html
Also refactored the file.