Beispiel #1
0
        public void ShowStatus()
        {
            Pidfile pidfile = new Pidfile();

            if (pidfile.IsValid())
            {
                Console.WriteLine("Watchdog is up and running");
            }
            else
            {
                Console.WriteLine("Watchdog is down");
            }
        }
Beispiel #2
0
        public void Daemonize()
        {
            Pidfile pidfile = new Pidfile();

            if (pidfile.IsValid())
            {
                Console.WriteLine("Process already started");
                return;
            }
            string mono = Environment.GetEnvironmentVariable("_");
            string app  = Environment.GetCommandLineArgs()[0];

            ProcessStartInfo startInfo = new ProcessStartInfo(mono, app + " " + "job");

            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            Process.Start(startInfo);
            Thread.Sleep(500);
        }
Beispiel #3
0
        public void Stop()
        {
            Pidfile pidfile = new Pidfile();

            if (pidfile.IsValid() && File.Exists(Location.Socket))
            {
                int    port = Convert.ToInt32(File.ReadAllText(Location.Socket));
                Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                sock.NoDelay  = true;
                sock.Blocking = true;
                sock.Connect("localhost", port);
                sock.Send(Encoding.ASCII.GetBytes("STOP\r\n"));
                byte[] buff = new byte[64];
                sock.Receive(buff);
                Thread.Sleep(500);
                sock.Close();
                pidfile.Delete();
                Console.WriteLine("Watchdog stopped");
            }
            else
            {
                Console.WriteLine("No watchdog is currently running");
            }
        }