| OLD | NEW |
| 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-present eyeo GmbH | 2 # Copyright (C) 2006-present 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 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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 |
| 42 if __name__ == '__main__': | 43 if __name__ == '__main__': |
| 43 services = _get_services() | 44 services = _get_services() |
| 44 for service in services.keys(): | 45 for service in services.keys(): |
| 45 pid_path = os.path.join('/var/run', services[service]) | 46 pid_path = os.path.join('/var/run', services[service]) |
| 46 if os.path.exists(pid_path): | 47 if os.path.exists(pid_path): |
| 47 with open(pid_path) as file: | 48 with open(pid_path) as file: |
| 48 pid_string = file.read() | 49 pid_string = file.read() |
| 49 | 50 |
| 50 try: | 51 try: |
| 51 pid = int(pid_string.rstrip()) | 52 pid = int(pid_string.rstrip()) |
| 52 if _process_running(pid): | 53 if _process_running(pid): |
| 53 continue | 54 continue |
| 54 except exceptions.ValueError: | 55 except exceptions.ValueError: |
| 55 print "'%s' is not a PID." % pid_string | 56 print "'%s' is not a PID." % pid_string |
| 56 | 57 |
| 57 init_path = os.path.join('/etc/init.d', service) | 58 init_path = os.path.join('/etc/init.d', service) |
| 58 if not os.path.exists(init_path): | 59 if not os.path.exists(init_path): |
| 59 print '%s does not exist, service is not running and cannot be start
ed.' % init_path | 60 print '%s does not exist, service is not running and cannot be start
ed.' % init_path |
| 60 continue | 61 continue |
| 61 | 62 |
| 62 print '%s is not running, starting ...' % service | 63 print '%s is not running, starting ...' % service |
| 63 subprocess.check_call([init_path, 'start']) | 64 subprocess.check_call([init_path, 'start']) |
| OLD | NEW |