Example #1
0
    protected override void OnStart(string[] args)
    {
        try
        {
            var svcDescription = SvcUtils.GetServiceDescriptionInSvcBin();
            var i   = svcDescription.LastIndexOf('<') + 1;
            var n   = svcDescription.Length - 1 - i;
            var cwd = svcDescription.Substring(i, n);
            Libs.SetCwd(cwd);
        }
        catch (Exception ex)
        {
            Libs.Dump($"Failed to set cwd from service's description:\r\n{ex}");
            Environment.Exit(1);
        }

        Conf = new Conf(false);

        try
        {
            Worker = new Worker(Conf, true);
            Worker.Start();
        }
        catch (Exception ex)
        {
            Conf.Abort($"Failed to start the worker:\r\n{ex}");
        }
    }
Example #2
0
    public void Cd()
    {
        if (!Directory.Exists(ConfDir))
        {
            Libs.Abort($"Service directory \"{ConfDir}\" not exists");
        }

        Libs.SetCwd(ConfDir);
    }
Example #3
0
 public static void SetCwdInSvcBin()
 {
     try
     {
         var description = GetServiceDescriptionInSvcBin();
         var cwd         = GetCwdInDescription(description);
         Libs.SetCwd(cwd);
     }
     catch (Exception ex)
     {
         Libs.Dump($"Failed to set cwd in service's bin, {ex}");
         Environment.Exit(1);
     }
 }
Example #4
0
    public static int Main(string[] args)
    {
        if (args.Length == 0)
        {
            SimpleService.RunService();
            return(0);
        }

        var op   = args[0];
        var opr  = $"|{op}|";
        var argc = args.Length - 1;
        var arg1 = argc == 1 ? args[1] : null;

        if (op == "version" || op == "--version" || op == "-v")
        {
            if (argc != 0)
            {
                Libs.Abort(USAGE);
            }

            Console.WriteLine(VERSION);
            return(0);
        }

        if (op == "create")
        {
            if (argc != 1)
            {
                Libs.Abort(USAGE);
            }

            CreateProject(arg1);
            return(0);
        }

        if (op == "list" || op == "ls")
        {
            if (argc != 0)
            {
                Libs.Abort(USAGE);
            }

            SvcUtils.ListAllEasyServices();
            return(0);
        }

        var commands = "|check|status|test-worker|install|stop|start|remove|restart|log|";

        if (!commands.Contains(opr) || argc > 1)
        {
            Libs.Abort(USAGE);
        }

        if (arg1 != null && (arg1.Contains('/') || arg1.Contains('\\')))
        {
            if (!Directory.Exists(arg1))
            {
                Libs.Abort($"Directory \"{arg1}\" not exists");
            }

            Libs.SetCwd(arg1);
            arg1 = null;
        }

        if (op == "test-worker")
        {
            if (arg1 != null && arg1 != "--popup")
            {
                Libs.Abort($"Directory argument \"{arg1}\" should contain '/' or '\\'");
            }

            TestWorker(arg1 == "--popup");
            return(0);
        }

        if ("|check|status|install|".Contains(opr) && arg1 != null)
        {
            Libs.Abort($"Directory argument \"{arg1}\" should contain '/' or '\\'");
        }

        if ("|restart|log|".Contains(opr) && arg1 == "all")
        {
            Libs.Abort(USAGE);
        }

        if (arg1 == null)
        {
            ManageOneByConfFile(op);
        }
        else if (arg1 != "all")
        {
            ManageOneBySvrIdentity(op, arg1);
        }
        else
        {
            SvcUtils.ManageAll(op);
        }

        return(0);
    }