2 # -*- coding: utf-8 -*-
4 # This file is part of Karesansui.
6 # Copyright (C) 2010 HDE, Inc.
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
17 from optparse import OptionParser
19 from ksscommand import KssCommand, KssCommandException, KssCommandOptException
24 from karesansui import __version__
25 from karesansui.lib.utils import load_locale
26 from karesansui.lib.service.sysvinit_rh import SysVInit_RH
27 from karesansui.lib.service.config import ServiceConfigParam
28 from karesansui.lib.const import SERVICE_XML_FILE
31 print >>sys.stderr, "[Error] karesansui package was not found."
36 usage = '%prog [options]'
39 optp = OptionParser(usage=usage, version=__version__)
40 optp.add_option('-n', '--name', dest='name', help=_('Service name'))
41 return optp.parse_args()
45 raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name')
47 class StartService(KssCommand):
50 (opts, args) = getopts()
54 config = ServiceConfigParam(SERVICE_XML_FILE)
55 config.load_xml_config()
57 service = config.findby1service(opts.name)
59 raise KssCommandException("Could not find the service - name=%s" % opts.name)
62 sysv = SysVInit_RH(service['system_name'], service['system_command'])
64 if sysv.start(force=False) is False:
65 raise KssCommandException(str(sysv.error_msg))
68 self.logger.info('Started service. - service=%s' % (opts.name))
69 print >>sys.stdout, _('Started service. - service=%s') % (opts.name)
73 if __name__ == "__main__":
74 target = StartService()
75 sys.exit(target.run())