ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Spectre2/Spectre2Control
(Generate patch)

Comparing Spectre2/Spectre2Control (file contents):
Revision 417 by douglas, 2005-03-02T14:49:53-08:00 vs.
Revision 418 by douglas, 2005-03-02T22:36:24-08:00

# Line 5 | Line 5
5   #
6   # $Id$
7  
8 < pid="spectre.pid"
8 > command="$1"
9  
10 < function usage()
10 > shift
11 >
12 > function check()
13   {
14 <        echo "Usage: `basename $0` start|stop|restart|reload|status [...]"
14 >        pid="$(< spectre.pid)"
15   }
16  
17 < #inline pid_t process()
18 < #{
19 < #       api::FileReader fin(pid);
20 < #
19 < #       return lexical_cast<pid_t>(ios::ReadLine(fin));
20 < #}
21 <
22 < #struct Spectre2Control : public app::Application
23 < #{
24 < #       virtual int Run(const app::ArgumentList& args)
25 < #       {
26 < #               enum Command { Start, Stop, Restart, Reload, Status } command;
27 < #
28 < #               if (!args.IsEmpty())
29 < #               {
30 < #                       const ext::String& arg(args.First());
31 < #
32 < #                       if (arg == "start") command = Start;
33 < #                       else if (arg == "stop") command = Stop;
34 < #                       else if (arg == "restart") command = Restart;
35 < #                       else if (arg == "reload") command = Reload;
36 < #                       else if (arg == "status") command = Status;
37 < #                       else return usage(1);
38 < #
39 < #                       _foreach (app::ArgumentList, arg, args)
40 < #                       {
41 < #                               Matcher matcher("^-pid=(.*)$");
42 < #
43 < #                               if (*arg == matcher) pid = matcher[1];
44 < #                       }
45 < #               }
46 < #               else return usage();
47 < #
48 < #               switch (command)
49 < #               {
50 < #               case Start:
51 < #                       start(args);
52 < #                       break;
53 < #               case Stop:
54 < #                       stop();
55 < #                       break;
56 < #               case Restart:
57 < #                       restart(args);
58 < #                       break;
59 < #               case Reload:
60 < #                       reload();
61 < #                       break;
62 < #               case Status:
63 < #                       status();
64 < #               }
65 < #
66 < #               return 0;
67 < #       }
68 < #} spectreControl;
17 > function usage()
18 > {
19 >        echo "Usage: $(basename $0) start|stop|restart|reload|status [...]"
20 > }
21  
22 < #void start(const app::ArgumentList& args)
23 < #{
24 < #       api::Cout << "Starting Spectre daemon ... " << ios::Flush;
25 < #
26 < #       if (pid_t process = api::Posix::CheckError(::fork()))
27 < #       {
76 < #               api::Cout << "started." << ios::NewLine;
77 < #       }
78 < #       else
79 < #       {
80 < #               _L<const char*> argv;
81 < #
82 < #               argv.Reserve(args.GetSize());
83 < #
84 < #               _foreach (app::ArgumentList, arg, args) argv.InsertLast(arg->NullTerminate());
85 < #
86 < #               ext::String command(api::GetExecutablePath().GetParent() + "Spectre2");
87 < #
88 < #               argv.First() = command.NullTerminate();
89 < #
90 < #               api::Posix::CheckError(::execv(command.NullTerminate(), const_cast<char**>(argv.NullTerminate())));
91 < #       }
92 < #}
22 > function start_()
23 > {
24 >        echo -n "Starting Spectre daemon ... "
25 >        $(dirname $0)/Spectre2 -fork $@
26 >        echo "started."
27 > }
28  
29 < #void stop()
30 < #{
31 < #       api::Cout << "Stopping Spectre daemon ... " << ios::Flush;
97 < #
29 > function stop_()
30 > {
31 >        echo -n "Stopping Spectre daemon ... "
32   #       try
33   #       {
34   #               pid_t id(process());
# Line 106 | Line 40 | function usage()
40   #               api::Cout << "stopped." << ios::NewLine;
41   #       }
42   #       catch (ext::Exception) { api::Cout << "failed." << ios::NewLine; }
43 < #}
43 > }
44  
45 < #void reload()
46 < #{
45 > function reload_()
46 > {
47 >        echo -n "Reloading Spectre daemon ... "
48   #       api::Cout << "Reloading Spectre daemon ... " << ios::Flush;
49   #
50   #       try
# Line 119 | Line 54 | function usage()
54   #               api::Cout << "reloaded." << ios::NewLine;
55   #       }
56   #       catch (ext::Exception) { api::Cout << "failed." << ios::NewLine; }
57 < #}
57 > }
58  
59 < #void status()
60 < #{
61 < #}
59 > function status_()
60 > {
61 >        echo "STUB: status_()"
62 > }
63  
64 < usage
64 > case $command in
65 > start)
66 >        start_ $@
67 >        ;;
68 > stop)
69 >        stop_
70 >        ;;
71 > restart)
72 >        restart_ $@
73 >        ;;
74 > reload)
75 >        reload_
76 >        ;;
77 > status)
78 >        status_
79 >        ;;
80 > *)
81 >        usage
82 >        ;;
83 > esac

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines