blob: 7da7c7a34aa8efbed6132f5085995f239e9ce51c [file] [log] [blame]
Jason Glasgow5395ed22011-08-19 13:16:47 -04001# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Ryan Harrisonb74d2242013-02-04 11:36:49 -05005"""Provides utility methods for interacting with upstart"""
Jason Glasgow5395ed22011-08-19 13:16:47 -04006
Paul Stewartf748e3b2011-09-12 15:04:11 -07007import os
Jason Glasgow5395ed22011-08-19 13:16:47 -04008
Andrey Ulanovec24bc22015-05-05 21:15:08 -07009from autotest_lib.client.common_lib import utils
10
Jason Glasgow5395ed22011-08-19 13:16:47 -040011def ensure_running(service_name):
Bertrand SIMONNETbd6cdb62014-07-01 12:25:27 -070012 """Fails if |service_name| is not running.
13
14 @param service_name: name of the service.
15 """
Jason Glasgow5395ed22011-08-19 13:16:47 -040016 cmd = 'initctl status %s | grep start/running' % service_name
Andrey Ulanovec24bc22015-05-05 21:15:08 -070017 utils.system(cmd)
Bertrand SIMONNETbd6cdb62014-07-01 12:25:27 -070018
19
20def has_service(service_name):
21 """Returns true if |service_name| is installed on the system.
22
23 @param service_name: name of the service.
24 """
25 return os.path.exists('/etc/init/' + service_name + '.conf')