systemctl: Create new unit files with "edit --force" (#3584)
This commit is contained in:
parent
ceeddf79b8
commit
39c38ce17c
4
TODO
4
TODO
|
@ -197,9 +197,7 @@ Features:
|
||||||
|
|
||||||
* systemctl: if some operation fails, show log output?
|
* systemctl: if some operation fails, show log output?
|
||||||
|
|
||||||
* systemctl edit:
|
* systemctl edit: use equvalent of cat() to insert existing config as a comment, prepended with #.
|
||||||
- allow creation of units from scratch
|
|
||||||
- use equvalent of cat() to insert existing config as a comment, prepended with #.
|
|
||||||
Upon editor exit, lines with one # are removed, lines with two # are left with one #, etc.
|
Upon editor exit, lines with one # are removed, lines with two # are left with one #, etc.
|
||||||
|
|
||||||
* exponential backoff in timesyncd when we cannot reach a server
|
* exponential backoff in timesyncd when we cannot reach a server
|
||||||
|
|
|
@ -481,6 +481,9 @@
|
||||||
<para>When used with <command>enable</command>, overwrite
|
<para>When used with <command>enable</command>, overwrite
|
||||||
any existing conflicting symlinks.</para>
|
any existing conflicting symlinks.</para>
|
||||||
|
|
||||||
|
<para>When used with <command>edit</command>, create all of the
|
||||||
|
specified units which do not already exist.</para>
|
||||||
|
|
||||||
<para>When used with <command>halt</command>, <command>poweroff</command>, <command>reboot</command> or
|
<para>When used with <command>halt</command>, <command>poweroff</command>, <command>reboot</command> or
|
||||||
<command>kexec</command>, execute the selected operation without shutting down all units. However, all
|
<command>kexec</command>, execute the selected operation without shutting down all units. However, all
|
||||||
processes will be killed forcibly and all file systems are unmounted or remounted read-only. This is hence a
|
processes will be killed forcibly and all file systems are unmounted or remounted read-only. This is hence a
|
||||||
|
@ -1303,6 +1306,9 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
|
||||||
<para>If <option>--full</option> is specified, this will copy the
|
<para>If <option>--full</option> is specified, this will copy the
|
||||||
original units instead of creating drop-in files.</para>
|
original units instead of creating drop-in files.</para>
|
||||||
|
|
||||||
|
<para>If <option>--force</option> is specified and any units do
|
||||||
|
not already exist, new unit files will be opened for editing.</para>
|
||||||
|
|
||||||
<para>If <option>--runtime</option> is specified, the changes will
|
<para>If <option>--runtime</option> is specified, the changes will
|
||||||
be made temporarily in <filename>/run</filename> and they will be
|
be made temporarily in <filename>/run</filename> and they will be
|
||||||
lost on the next reboot.</para>
|
lost on the next reboot.</para>
|
||||||
|
|
|
@ -2499,7 +2499,7 @@ static int unit_find_paths(
|
||||||
r = 1;
|
r = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r == 0)
|
if (r == 0 && !arg_force)
|
||||||
log_error("No files found for %s.", unit_name);
|
log_error("No files found for %s.", unit_name);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
@ -6070,7 +6070,7 @@ static int create_edit_temp_file(const char *new_path, const char *original_path
|
||||||
return log_error_errno(r, "Failed to create temporary file \"%s\": %m", t);
|
return log_error_errno(r, "Failed to create temporary file \"%s\": %m", t);
|
||||||
|
|
||||||
} else if (r < 0)
|
} else if (r < 0)
|
||||||
return log_error_errno(r, "Failed to copy \"%s\" to \"%s\": %m", original_path, t);
|
return log_error_errno(r, "Failed to create temporary file for \"%s\": %m", new_path);
|
||||||
|
|
||||||
*ret_tmp_fn = t;
|
*ret_tmp_fn = t;
|
||||||
t = NULL;
|
t = NULL;
|
||||||
|
@ -6114,9 +6114,10 @@ static int get_file_to_edit(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unit_file_create_dropin(
|
static int unit_file_create_new(
|
||||||
const LookupPaths *paths,
|
const LookupPaths *paths,
|
||||||
const char *unit_name,
|
const char *unit_name,
|
||||||
|
const char *suffix,
|
||||||
char **ret_new_path,
|
char **ret_new_path,
|
||||||
char **ret_tmp_path) {
|
char **ret_tmp_path) {
|
||||||
|
|
||||||
|
@ -6127,7 +6128,7 @@ static int unit_file_create_dropin(
|
||||||
assert(ret_new_path);
|
assert(ret_new_path);
|
||||||
assert(ret_tmp_path);
|
assert(ret_tmp_path);
|
||||||
|
|
||||||
ending = strjoina(unit_name, ".d/override.conf");
|
ending = strjoina(unit_name, suffix);
|
||||||
r = get_file_to_edit(paths, ending, &tmp_new_path);
|
r = get_file_to_edit(paths, ending, &tmp_new_path);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -6180,7 +6181,6 @@ static int unit_file_create_copy(
|
||||||
|
|
||||||
r = create_edit_temp_file(tmp_new_path, fragment_path, &tmp_tmp_path);
|
r = create_edit_temp_file(tmp_new_path, fragment_path, &tmp_tmp_path);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_error_errno(r, "Failed to create temporary file for \"%s\": %m", tmp_new_path);
|
|
||||||
free(tmp_new_path);
|
free(tmp_new_path);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -6291,18 +6291,26 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
|
||||||
r = unit_find_paths(bus, *name, &lp, &path, NULL);
|
r = unit_find_paths(bus, *name, &lp, &path, NULL);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
else if (r == 0)
|
else if (!arg_force) {
|
||||||
return -ENOENT;
|
if (r == 0) {
|
||||||
else if (!path) {
|
log_error("Run 'systemctl edit --force %s' to create a new unit.", *name);
|
||||||
// FIXME: support units with path==NULL (no FragmentPath)
|
return -ENOENT;
|
||||||
log_error("No fragment exists for %s.", *name);
|
} else if (!path) {
|
||||||
return -ENOENT;
|
// FIXME: support units with path==NULL (no FragmentPath)
|
||||||
|
log_error("No fragment exists for %s.", *name);
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path) {
|
||||||
|
if (arg_full)
|
||||||
|
r = unit_file_create_copy(&lp, *name, path, &new_path, &tmp_path);
|
||||||
|
else
|
||||||
|
r = unit_file_create_new(&lp, *name, ".d/override.conf", &new_path, &tmp_path);
|
||||||
|
} else {
|
||||||
|
r = unit_file_create_new(&lp, *name, NULL, &new_path, &tmp_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg_full)
|
|
||||||
r = unit_file_create_copy(&lp, *name, path, &new_path, &tmp_path);
|
|
||||||
else
|
|
||||||
r = unit_file_create_dropin(&lp, *name, &new_path, &tmp_path);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue