diff options
Diffstat (limited to 'meta-webserver/recipes-webadmin/ajenti/ajenti/0006-plugins-services-add-basic-sysvinit-implementation.patch')
-rw-r--r-- | meta-webserver/recipes-webadmin/ajenti/ajenti/0006-plugins-services-add-basic-sysvinit-implementation.patch | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/meta-webserver/recipes-webadmin/ajenti/ajenti/0006-plugins-services-add-basic-sysvinit-implementation.patch b/meta-webserver/recipes-webadmin/ajenti/ajenti/0006-plugins-services-add-basic-sysvinit-implementation.patch new file mode 100644 index 000000000..651018e5a --- /dev/null +++ b/meta-webserver/recipes-webadmin/ajenti/ajenti/0006-plugins-services-add-basic-sysvinit-implementation.patch | |||
@@ -0,0 +1,119 @@ | |||
1 | From 57f949a7ab34812d8384bf41c05c3b25bdade92b Mon Sep 17 00:00:00 2001 | ||
2 | From: Paul Eggleton <paul.eggleton@linux.intel.com> | ||
3 | Date: Sun, 18 Mar 2012 14:26:34 +0000 | ||
4 | Subject: [PATCH] plugins/services: add basic sysvinit implementation | ||
5 | |||
6 | This allows operation on systems that don't have the "service" command. | ||
7 | The PID finding is a little hacky but mostly works. Note that this uses | ||
8 | psutil to detect whether the service is really running rather than just | ||
9 | assuming that it is if the pid file exists. | ||
10 | |||
11 | Note: you need to remove s_upstart.py before this will work. | ||
12 | |||
13 | Upstream-Status: Pending | ||
14 | |||
15 | Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> | ||
16 | --- | ||
17 | plugins/services/s_init.py | 90 ++++++++++++++++++++++++++++++++++++++++++++ | ||
18 | 1 files changed, 90 insertions(+), 0 deletions(-) | ||
19 | create mode 100755 plugins/services/s_init.py | ||
20 | |||
21 | diff --git a/plugins/services/s_init.py b/plugins/services/s_init.py | ||
22 | new file mode 100755 | ||
23 | index 0000000..6f38b0a | ||
24 | --- /dev/null | ||
25 | +++ b/plugins/services/s_init.py | ||
26 | @@ -0,0 +1,90 @@ | ||
27 | +# Basic sysvinit service backend implementation for Ajenti Services plugin | ||
28 | +# | ||
29 | +# Copyright (C) 2012 Intel Corporation | ||
30 | +# Author: Paul Eggleton <paul.eggleton@linux.intel.com> | ||
31 | +# | ||
32 | + | ||
33 | +import os | ||
34 | +import psutil | ||
35 | + | ||
36 | +from ajenti.com import * | ||
37 | +from ajenti.utils import * | ||
38 | +from ajenti import apis | ||
39 | +from ajenti.api import * | ||
40 | + | ||
41 | +def find_service_pid(service): | ||
42 | + svcfile = os.path.join('/etc/init.d', service) | ||
43 | + pidfile = '' | ||
44 | + try: | ||
45 | + svcf = open(svcfile) | ||
46 | + except: | ||
47 | + return None | ||
48 | + while 1: | ||
49 | + line = svcf.readline() | ||
50 | + if not line: | ||
51 | + break | ||
52 | + if line.startswith('PID='): | ||
53 | + pidfile = line.split('=')[1].strip("'\n\r \"") | ||
54 | + break | ||
55 | + svcf.close() | ||
56 | + if not pidfile: | ||
57 | + pf = '/var/run/%s.pid' % service | ||
58 | + if os.path.exists(pf): | ||
59 | + pidfile = pf | ||
60 | + else: | ||
61 | + pf = '/var/run/%sd.pid' % service | ||
62 | + if os.path.exists(pf): | ||
63 | + pidfile = pf | ||
64 | + if pidfile: | ||
65 | + pidf = open(pidfile) | ||
66 | + pid = pidf.readline() | ||
67 | + pidf.close | ||
68 | + if pid: | ||
69 | + pid = pid.strip() | ||
70 | + pid = int(pid) | ||
71 | + try: | ||
72 | + p = psutil.Process(pid) | ||
73 | + except: | ||
74 | + pid = None | ||
75 | + return pid | ||
76 | + return None | ||
77 | + | ||
78 | + | ||
79 | +class UpstartServiceManager(Plugin): | ||
80 | + implements(apis.services.IServiceManager) | ||
81 | + platform = ['debian'] | ||
82 | + | ||
83 | + def list_all(self): | ||
84 | + r = [] | ||
85 | + | ||
86 | + blacklist = 'functions mountall.sh save-rtc.sh umountnfs.sh populate-volatile.sh rcS bootlogd urandom halt sendsigs single bootmisc.sh sysfs.sh mountnfs.sh busybox-udhcpc devpts.sh banner.sh modutils.sh checkroot.sh networking umountfs udev rc hostname.sh fbsetup stop-bootlogd rmnologin.sh reboot hwclock.sh read-only-rootfs-hook.sh functions.initscripts syslog.busybox'.split() | ||
87 | + | ||
88 | + for f in os.listdir('/etc/init.d'): | ||
89 | + if not f in blacklist: | ||
90 | + svc = apis.services.Service() | ||
91 | + svc.name = f | ||
92 | + pid = find_service_pid(f) | ||
93 | + if pid: | ||
94 | + svc.status = 'running' | ||
95 | + else: | ||
96 | + svc.status = 'stopped' | ||
97 | + r.append(svc) | ||
98 | + | ||
99 | + return sorted(r, key=lambda s: s.name) | ||
100 | + | ||
101 | + def get_status(self, name): | ||
102 | + pid = find_service_pid(name) | ||
103 | + if pid: | ||
104 | + return 'running' | ||
105 | + else: | ||
106 | + return 'stopped' | ||
107 | + | ||
108 | + def start(self, name): | ||
109 | + shell('/etc/init.d/%s start' % name) | ||
110 | + | ||
111 | + def stop(self, name): | ||
112 | + shell('/etc/init.d/%s stop' % name) | ||
113 | + | ||
114 | + def restart(self, name): | ||
115 | + shell('/etc/init.d/%s restart' % name) | ||
116 | + | ||
117 | -- | ||
118 | 1.7.5.4 | ||
119 | |||