00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <basis/istring.h>
00016 #include <loggers/console_logger.h>
00017 #include <opsystem/application_shell.h>
00018 #include <opsystem/filename.h>
00019 #include <data_struct/static_memory_gremlin.h>
00020 #include <service_ext/service_control.h>
00021
00022 const int SERVICE_SHUTDOWN_DELAY = 4 * SECOND_ms;
00023
00024
00025
00026
00027 class service_controller : public application_shell
00028 {
00029 public:
00030 service_controller() : application_shell(class_name()) {}
00031
00032 virtual int execute();
00033
00034 IMPLEMENT_CLASS_NAME("service_controller");
00035
00036 int instruct();
00037
00038 };
00039
00041
00042 int service_controller::instruct()
00043 {
00044 log(filename(__argv[0]).rootname() + " Usage:");
00045 log("\
00046 This program provides control over services in MS-Win32 operating systems.\n\
00047 The first parameter must be \"start\", \"stop\", \"restart\", \"manual\", or\n\
00048 \"automatic\". This specifies how to control the service. The second\n\
00049 parameter is the name of the service. This must be identical to the service\n\
00050 name registered with the operating system. The start, stop and restart\n\
00051 flags operate on the running state of a service. The manual and automatic\n\
00052 flags simply change the service launch configuration.\n\
00053 \n\
00054 Example:\n\
00055 \tservice_controller restart app_launcher\n");
00056 return 1;
00057 }
00058
00059 int service_controller::execute()
00060 {
00061 SET_DEFAULT_CONSOLE_LOGGER;
00062 if (__argc < 3) return instruct();
00063
00064 istring control_word(__argv[1]);
00065 control_word.to_lower();
00066
00067 istring service_name(__argv[2]);
00068 service_name.to_lower();
00069
00070 service_control ctl;
00071
00072 if (control_word == "stop")
00073 return !(ctl.control_service(service_name, false, false)
00074 == service_control::OKAY);
00075 else if (control_word == "start")
00076 return !(ctl.control_service(service_name, true, false)
00077 == service_control::OKAY);
00078 else if (control_word == "restart") {
00079
00080
00081 ctl.control_service(service_name, false, true);
00082
00083 portable::sleep_ms(SERVICE_SHUTDOWN_DELAY);
00084 return !(ctl.control_service(service_name, true, false)
00085 == service_control::OKAY);
00086 } else if (control_word == "manual") {
00087 return !(ctl.reconfigure_service(service_name, service_control::MANUAL)
00088 == service_control::OKAY);
00089 } else if (control_word == "automatic") {
00090 return !(ctl.reconfigure_service(service_name, service_control::AUTOMATIC)
00091 == service_control::OKAY);
00092 } else return instruct();
00093 }
00094
00096
00097 HOOPLE_MAIN(service_controller, )
00098
00099 #ifdef __BUILD_STATIC_APPLICATION__
00100
00101 #include <basis/array.cpp>
00102 #include <basis/byte_array.cpp>
00103 #include <basis/callstack_tracker.cpp>
00104 #include <basis/chaos.cpp>
00105 #include <basis/convert_utf.cpp>
00106 #include <basis/definitions.cpp>
00107 #include <basis/earth_time.cpp>
00108 #include <basis/guards.cpp>
00109 #include <basis/istring.cpp>
00110 #include <basis/log_base.cpp>
00111 #include <basis/memory_checker.cpp>
00112 #include <basis/mutex.cpp>
00113 #include <basis/object_base.cpp>
00114 #include <basis/outcome.cpp>
00115 #include <basis/packable.cpp>
00116 #include <basis/portable.cpp>
00117 #include <basis/sequence.cpp>
00118 #include <basis/set.cpp>
00119 #include <basis/utility.cpp>
00120 #include <basis/version_record.cpp>
00121 #include <data_struct/amorph.cpp>
00122 #include <data_struct/bit_vector.cpp>
00123 #include <data_struct/byte_hasher.cpp>
00124 #include <data_struct/configurator.cpp>
00125 #include <data_struct/hash_table.cpp>
00126 #include <data_struct/pointer_hash.cpp>
00127 #include <data_struct/stack.cpp>
00128 #include <data_struct/static_memory_gremlin.cpp>
00129 #include <data_struct/string_hash.cpp>
00130 #include <data_struct/string_hasher.cpp>
00131 #include <data_struct/string_table.cpp>
00132 #include <data_struct/symbol_table.cpp>
00133 #include <data_struct/table_configurator.cpp>
00134 #include <loggers/console_logger.cpp>
00135 #include <loggers/file_logger.cpp>
00136 #include <loggers/locked_logger.cpp>
00137 #include <loggers/null_logger.cpp>
00138 #include <loggers/program_wide_logger.cpp>
00139 #include <opsystem/application_base.cpp>
00140 #include <opsystem/application_shell.cpp>
00141 #include <opsystem/byte_filer.cpp>
00142 #include <opsystem/command_line.cpp>
00143 #include <opsystem/critical_events.cpp>
00144 #include <opsystem/directory.cpp>
00145 #include <opsystem/filename.cpp>
00146 #include <opsystem/ini_config.cpp>
00147 #include <opsystem/ini_parser.cpp>
00148 #include <opsystem/path_configuration.cpp>
00149 #include <opsystem/rendezvous.cpp>
00150 #include <service_ext/service_control.cpp>
00151 #include <textual/byte_format.cpp>
00152 #include <textual/parser_bits.cpp>
00153 #include <textual/string_manipulation.cpp>
00154 #include <textual/tokenizer.cpp>
00155 #endif // __BUILD_STATIC_APPLICATION__
00156