View | Details | Raw Unified | Return to bug 664548
Collapse All | Expand All

(-)library/runlevel/src/Makefile.am (+1 lines)
Lines 9-12 Link Here
9
EXTRA_DIST = $(agent_SCRIPTS)	\
9
EXTRA_DIST = $(agent_SCRIPTS)	\
10
	$(scrconf_DATA) $(module_DATA)
10
	$(scrconf_DATA) $(module_DATA)
11
11
12
YCPCFLAGS = -M ../../types/src -M ../../modules
12
include $(top_srcdir)/Makefile.am.common
13
include $(top_srcdir)/Makefile.am.common
(-)library/runlevel/src/Service.ycp (-17 / +30 lines)
Lines 18-23 Link Here
18
module "Service";
18
module "Service";
19
textdomain "base";
19
textdomain "base";
20
20
21
import "FileUtils";
22
21
/***
23
/***
22
 * Services Manipulation
24
 * Services Manipulation
23
 */
25
 */
Lines 44-52 Link Here
44
 */
46
 */
45
47
46
/**
48
/**
49
 * Program to invoke the service init scripts, or the systemd actions
50
 */
51
string invoker = "/sbin/service";
52
/**
47
 * Script location
53
 * Script location
48
 */
54
 */
49
string init_d = "/etc/init.d";
55
string init_d = "/etc/init.d";
56
/**
57
 * Unit location for systemd
58
 */
59
string systemd_d = "/lib/systemd/system";
50
60
51
/**
61
/**
52
 * After a function returns an error, this holds an error message,
62
 * After a function returns an error, this holds an error message,
Lines 74-80 Link Here
74
	y2error(1, error_msg);
84
	y2error(1, error_msg);
75
	return false;
85
	return false;
76
    }
86
    }
77
    if(! (boolean) SCR::Read(.init.scripts.exists, name)) {
87
    if (FileUtils::Exists(sformat("%1/%2", init_d,name))) {
88
	return true;
89
    }
90
    else if (FileUtils::Exists(sformat("%1/%2.service", systemd_d,name))) {
91
	return true;
92
    }
93
    else {
78
	// Error message.
94
	// Error message.
79
	// %1 is a name of an init script in /etc/init.d,
95
	// %1 is a name of an init script in /etc/init.d,
80
	// eg. nfsserver
96
	// eg. nfsserver
Lines 82-88 Link Here
82
	y2milestone (1, error_msg);
98
	y2milestone (1, error_msg);
83
	return false;
99
	return false;
84
    }
100
    }
85
    return true;
86
}
101
}
87
102
88
/**
103
/**
Lines 111-117 Link Here
111
 */
126
 */
112
global define integer Status (string name) {
127
global define integer Status (string name) {
113
    if(!checkExists (name)) return -1;
128
    if(!checkExists (name)) return -1;
114
    return (integer) SCR::Execute (.target.bash, sformat ("%2/%1 status", name, init_d), $["TERM":"raw"]);
129
    return (integer) SCR::Execute (.target.bash, sformat ("%1 %2 status", invoker, name), $["TERM":"raw"]);
115
}
130
}
116
131
117
/**
132
/**
Lines 133-140 Link Here
133
 */
148
 */
134
define boolean serviceDisable (string name, boolean force) {
149
define boolean serviceDisable (string name, boolean force) {
135
    map ret = (map)SCR::Execute (.target.bash_output,
150
    map ret = (map)SCR::Execute (.target.bash_output,
136
			    sformat ("/sbin/insserv -r%3 %2/%1",
151
			    sformat ("/sbin/chkconfig -d%2 %1",
137
				     name, init_d, force? "f": ""));
152
				     name, force? "f": ""));
138
    if (0 != ret["exit"]:-1)
153
    if (0 != ret["exit"]:-1)
139
    {
154
    {
140
	// Error message.
155
	// Error message.
Lines 166-174 Link Here
166
	return false;
181
	return false;
167
    }
182
    }
168
    map service = Info (name);
183
    map service = Info (name);
184
    boolean is_enabled = size (service["start"]:[]) != 0;
169
    if ("disable" == action)
185
    if ("disable" == action)
170
    {
186
    {
171
	if (size (service["start"]:[]) != 0)
187
	if (is_enabled)
172
	{
188
	{
173
	    return serviceDisable (name, false);
189
	    return serviceDisable (name, false);
174
	}
190
	}
Lines 176-182 Link Here
176
    }
192
    }
177
    if (("default" == action) || ("enable" == action))
193
    if (("default" == action) || ("enable" == action))
178
    {
194
    {
179
	if ("enable" == action && size (service["start"]:[]) != 0)
195
	if ("enable" == action && is_enabled)
180
	{
196
	{
181
	    // nothing to do
197
	    // nothing to do
182
	    return true;
198
	    return true;
Lines 184-191 Link Here
184
	else
200
	else
185
	{
201
	{
186
	    map ret = (map)SCR::Execute (.target.bash_output,
202
	    map ret = (map)SCR::Execute (.target.bash_output,
187
				    sformat ("/sbin/insserv -d %2/%1",
203
				    sformat ("/sbin/chkconfig -a %1",
188
					     name, init_d));
204
					     name));
189
	    if (0 != ret["exit"]:-1)
205
	    if (0 != ret["exit"]:-1)
190
	    {
206
	    {
191
		// Error message.
207
		// Error message.
Lines 262-280 Link Here
262
}
278
}
263
279
264
/**
280
/**
265
 * Check if service is enabled
281
 * Check if service is enabled (in RL 3 or multi-user.target)
266
 *
282
 *
267
 * Returns true if any link in /etc/init.d/rc?.d/ exists for this
283
 * Forwards to chkconfig -c which decides between init and systemd
268
 * script. If service does not exist, logs an error.
269
 *
284
 *
270
 * @param name service name
285
 * @param name service name
271
 * @return true if service is set to run in any runlevel
286
 * @return true if service is set to run
272
 */
287
 */
273
global define boolean Enabled (string name) {
288
global define boolean Enabled (string name) {
274
    if(!checkExists (name)) return false;
289
    if(!checkExists (name)) return false;
275
    map<string, any> details = (map<string, any>) SCR::Read (.init.scripts.runlevel, name);
290
    return 0 == SCR::Execute (.target.bash, sformat ("chkconfig -c %1 3", name));
276
    map<string, any> detail  = (map<string, any>) details[name]:$[];
277
    return size(detail["start"]:[]) != 0;
278
}
291
}
279
292
280
/**
293
/**
Lines 285-291 Link Here
285
 */
298
 */
286
global define integer RunInitScript (string name, string param) {
299
global define integer RunInitScript (string name, string param) {
287
    y2milestone("Running service initscript %1 %2", name, param);
300
    y2milestone("Running service initscript %1 %2", name, param);
288
    string command = sformat ("%2/%1 %3", name, init_d, param);
301
    string command = sformat ("%1 %2 %3", invoker, name, param);
289
    map<string, any> output=(map<string, any>)SCR::Execute (.target.bash_output,
302
    map<string, any> output=(map<string, any>)SCR::Execute (.target.bash_output,
290
	    command, $[ "TERM" : "raw"]);
303
	    command, $[ "TERM" : "raw"]);
291
304

Return to bug 664548