Portál AbcLinuxu, 29. července 2025 01:27
drakxservices
, zobrazí název - stav - jestli se má poutět při startu - tlačítko spustit/zastavit. Ale ikonky to žádný nemá #!/usr/bin/env python import subprocess, gtk services = ['httpd', 'vsftpd', 'cups'] class Services: def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("service controller") self.window.set_position(gtk.WIN_POS_CENTER) self.window.connect('delete_event', self.delete_event) self.window.connect('destroy', self.quit) self.box = gtk.VBox(False, 0) for service in services: button = gtk.ToggleButton(service) button.set_active(self.is_service_running(service)) button.connect('clicked', self.clicked_cb, service) button.show() self.box.pack_start(button, True, True, 0) self.box.show() self.window.add(self.box) self.window.show() def is_service_running(self, service): cmd = ['/etc/init.d/' + service, 'status'] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) return 'running' in proc.stdout.read() def clicked_cb(self, widget, service): if widget.get_active(): print 'starting service', service cmd = ['/etc/init.d/' + service, 'start'] else: print 'stopping service', service cmd = ['/etc/init.d/' + service, 'stop'] subprocess.call(cmd) def delete_event(self, widget, data): return False def quit(self, widget, data = None): gtk.main_quit() def main(self): gtk.main() s = Services() s.main()Musí se to pouštět jako root, což vyžaduje trochu odvahy. Jde spíš o ukázku řešení, napadá mě spousta situací, kdy to nebude spolehlivé
button = gtk.CheckButton(service)
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.