Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/management/bin/start_services.py

Issue 29345242: Noissue - Adapt quotes for compliance with our coding style in sitescripts (Closed)
Patch Set: Fixed raw string Created May 30, 2016, 8:47 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import exceptions 16 import exceptions
17 import os 17 import os
18 import subprocess 18 import subprocess
19 from sitescripts.utils import get_config 19 from sitescripts.utils import get_config
20 20
21 21
22 def _get_services(): 22 def _get_services():
23 config = get_config() 23 config = get_config()
24 section_name = "keep_alive_services" 24 section_name = 'keep_alive_services'
25 section_keys = config.options(section_name) 25 section_keys = config.options(section_name)
26 default_keys = config.defaults().keys() 26 default_keys = config.defaults().keys()
27 keys = set(section_keys) - set(default_keys) 27 keys = set(section_keys) - set(default_keys)
28 28
29 services = {} 29 services = {}
30 for key in keys: 30 for key in keys:
31 services[key] = config.get(section_name, key) 31 services[key] = config.get(section_name, key)
32 return services 32 return services
33 33
34 34
35 def _process_running(pid): 35 def _process_running(pid):
36 try: 36 try:
37 os.kill(pid, 0) 37 os.kill(pid, 0)
38 return True 38 return True
39 except OSError: 39 except OSError:
40 return False 40 return False
41 41
42 if __name__ == "__main__": 42 if __name__ == '__main__':
43 services = _get_services() 43 services = _get_services()
44 for service in services.keys(): 44 for service in services.keys():
45 pid_path = os.path.join("/var/run", services[service]) 45 pid_path = os.path.join('/var/run', services[service])
46 if os.path.exists(pid_path): 46 if os.path.exists(pid_path):
47 with open(pid_path) as file: 47 with open(pid_path) as file:
48 pid_string = file.read() 48 pid_string = file.read()
49 49
50 try: 50 try:
51 pid = int(pid_string.rstrip()) 51 pid = int(pid_string.rstrip())
52 if _process_running(pid): 52 if _process_running(pid):
53 continue 53 continue
54 except exceptions.ValueError: 54 except exceptions.ValueError:
55 print "'%s' is not a PID." % pid_string 55 print "'%s' is not a PID." % pid_string
56 56
57 init_path = os.path.join("/etc/init.d", service) 57 init_path = os.path.join('/etc/init.d', service)
58 if not os.path.exists(init_path): 58 if not os.path.exists(init_path):
59 print "%s does not exist, service is not running and cannot be start ed." % init_path 59 print '%s does not exist, service is not running and cannot be start ed.' % init_path
60 continue 60 continue
61 61
62 print "%s is not running, starting ..." % service 62 print '%s is not running, starting ...' % service
63 subprocess.check_call([init_path, "start"]) 63 subprocess.check_call([init_path, 'start'])
OLDNEW

Powered by Google App Engine
This is Rietveld