Ensuring file sharing stays enabled MacOS

Proper tools in macOS client are sharing and launchctl which have to be run as root:

Check man sharing how to use it.

To start/stop or load AFP or SMB use:

sudo launchctl [subcommand] -w /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist

or

sudo launchctl [subcommand] -w /System/Library/LaunchDaemons/com.apple.smbd.plist

The proper tool to deal with macOS server related tasks is serveradmin which has to be run as root:

sudo serveradmin -h
Usage: serveradmin [-dhvx] [list | start | stop | status | fullstatus | settings | command] [<service_key> [ = <value> ]]

  -h, --help     display this message
  -v, --version  display version info
  -d, --debug    print command
  -x, --xml      print output as XML plist
Examples:
serveradmin list
    --Lists all services
serveradmin start afp
    --Starts afp server
serveradmin stop ftp
    --Stops ftp server
serveradmin status web
    --Returns current status of the web server
serveradmin fullstatus web
    --Returns more complete status of the web server
serveradmin settings afp
    --Returns all afp configuration parameters
serveradmin settings afp:guestAccess
    --Returns afp guestAccess attribute
serveradmin settings afp:guestAccess = yes
    --Sets afp guestAccess to true
serveradmin settings
    --Takes settings commands like above from stdin
serveradmin command afp:command = getConnectedUsers
    --Used to perform service specific commands
serveradmin command
    --Takes stdin to define generic command that requires other parameters