correct way to shutdown photon server

Options
BesoC
BesoC ✭✭
edited June 2013 in Photon Server
What is the correct way to stop Photon server from server code?

Comments

  • chvetsov
    Options
    there is no way to do this
  • Tobias
    Options
    You could run an external task/process, which in turn can tell the server to stop.
    The *.cmd files in the server SDK could be called. Look at _service.stop.cmd and _run-Photon-as-application.stop.cmd

    Why do you want to do this?
  • BesoC
    BesoC ✭✭
    Options
    well, i want the server to check some hardware and software conditions and halt if they are not met. The only way i think of is to call AppDomain.Unload(AppDomain.CurrentDomain). If this call is performed in Setup() then it works and server is stopped. However, if it's called from any other part of code, then domain unloads and became re-loaded automatically.
  • Yes, that makes sense:

    If the app domain is unloaded during setup, the app was in fact not loaded successfully - and Photon will not start if it fails to load an application.

    You can probably prevent the automatic reloads by setting the ForceAutoRestart="false" and "EnableAutoRestart="false" for each <Application> node in your PhotonServer.config - but this should only leave you with a running Photon instance in which the applications are unloaded; Photon itself will keep running.

    The easiest approach is probably to install Photon as a service and call this:
    var service =
                      ServiceController.GetServices().FirstOrDefault(
                          svc =&gt; svc.ServiceName.Equals("Photon Socket Server: Default"));
    
                if (service != null && service.Status == ServiceControllerStatus.Running)
                {
                    service.Stop();
                }