Example #1
0
        private void HandleProcessExit(Unit unit, ProcessInfo info, int code)
        {
            switch (CurrentState)
            {
            case UnitState.Deactivating:
                SetState(UnitState.Inactive);
                break;

            default:
                // TODO: treat process exit differently based on service type
                if (code != 0)
                {
                    SetState(UnitState.Failed);
                }
                else
                {
                    SetState(UnitState.Inactive);
                }

                var should_restart = false;

                if (code == 0)
                {
                    should_restart =
                        Descriptor.Restart == RestartBehavior.Always ||
                        Descriptor.Restart == RestartBehavior.OnSuccess;
                }
                else
                {
                    should_restart =
                        Descriptor.Restart == RestartBehavior.Always ||
                        Descriptor.Restart == RestartBehavior.OnFailure ||
                        Descriptor.Restart == RestartBehavior.OnAbnormal;
                }

                if (should_restart)
                {
                    var restart_transaction = new Transaction(
                        new DelayTask(Descriptor.RestartSec),
                        UnitRegistry.CreateDeactivationTransaction(UnitName),
                        UnitRegistry.CreateActivationTransaction(UnitName));

                    // TODO: un-hack this
                    new Thread((ThreadStart) delegate { restart_transaction.Execute(); }).Start();
                }
                break;
            }
        }
Example #2
0
 public OnDiskUnitFile(string path)
 {
     Path      = path;
     UnitName  = UnitRegistry.GetUnitName(path);
     Extension = System.IO.Path.GetExtension(UnitName);
 }