blob: 038c8ba374f589d9f0b53d3f7c17b781677e2c52 [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
9def ensure_running(service_name):
Bertrand SIMONNETbd6cdb62014-07-01 12:25:27 -070010 """Fails if |service_name| is not running.
11
12 @param service_name: name of the service.
13 """
Jason Glasgow5395ed22011-08-19 13:16:47 -040014 cmd = 'initctl status %s | grep start/running' % service_name
Paul Stewartf748e3b2011-09-12 15:04:11 -070015 os.system(cmd)
Bertrand SIMONNETbd6cdb62014-07-01 12:25:27 -070016
17
18def has_service(service_name):
19 """Returns true if |service_name| is installed on the system.
20
21 @param service_name: name of the service.
22 """
23 return os.path.exists('/etc/init/' + service_name + '.conf')