Bug 1316387

Summary: systemctl preset-all disables but wont enable default.target
Product: Red Hat Enterprise Linux 7 Reporter: Aaron Howell <bugzilla>
Component: systemdAssignee: Jan Synacek <jsynacek>
Status: CLOSED NOTABUG QA Contact: qe-baseos-daemons
Severity: low Docs Contact:
Priority: unspecified    
Version: 7.2CC: bugzilla, dshaw, fsumsal, msekleta, sjayapra, systemd-maint-list
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-06-13 11:42:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 1298243, 1420851, 1549617, 1551061    

Description Aaron Howell 2016-03-10 07:19:49 UTC
Description of problem:
systemctl preset-all disables but wont enable default.target.
So if the target is not enabled in preset policy it is removed. If it is enabled in default policy however it is not added. This is confusing behaviour.

It should either work for both or none. 

Version-Release number of selected component (if applicable):
systemd-219-19.el7_2.4.x86_64

How reproducible:
Everytime

Steps to Reproduce:
1. # No reference to multi-user.target in any systemd-preset files (ie uses 99-default.preset)
2. sudo systemctl preset-all
3. # Add "enable multi-user.target" to a systemd-preset file (eg /etc/systemd/system-preset/01-target.preset)
4. sudo systemctl preset-all

Actual results:
$ sudo systemctl status multi-user.target 
● multi-user.target - Multi-User System
   Loaded: loaded (/usr/lib/systemd/system/multi-user.target; static; vendor preset: disabled)
   Active: active since Wed 2016-03-09 15:57:02 AEDT; 1 day 1h ago
     Docs: man:systemd.special(7)
$ sudo systemctl get-default 
multi-user.target
$ sudo systemctl preset-all
Removed symlink /etc/systemd/system/default.target.
$sudo systemctl get-default 
graphical.target
$ echo "enable multi-user.target" >> sudo tee -a /etc/systemd/system-preset/01-target.preset
$ sudo systemctl daemon-reload
$ sudo systemctl status multi-user.target 
● multi-user.target - Multi-User System
   Loaded: loaded (/usr/lib/systemd/system/multi-user.target; static; vendor preset: enabled)
   Active: active since Wed 2016-03-09 15:57:02 AEDT; 1 day 1h ago
     Docs: man:systemd.special(7)
$ sudo systemctl preset-all
$ sudo systemctl get-default 
graphical.target

Expected results:
# Work for both
$ sudo systemctl status multi-user.target 
● multi-user.target - Multi-User System
   Loaded: loaded (/usr/lib/systemd/system/multi-user.target; static; vendor preset: disabled)
   Active: active since Wed 2016-03-09 15:57:02 AEDT; 1 day 1h ago
     Docs: man:systemd.special(7)
$ sudo systemctl get-default 
multi-user.target
$ sudo systemctl preset-all
Removed symlink /etc/systemd/system/default.target.
$sudo systemctl get-default 
graphical.target
$ echo "enable multi-user.target" >> sudo tee -a /etc/systemd/system-preset/01-target.preset
$ sudo systemctl daemon-reload
$ sudo systemctl status multi-user.target 
● multi-user.target - Multi-User System
   Loaded: loaded (/usr/lib/systemd/system/multi-user.target; static; vendor preset: enabled)
   Active: active since Wed 2016-03-09 15:57:02 AEDT; 1 day 1h ago
     Docs: man:systemd.special(7)
$ sudo systemctl preset-all
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
$ sudo systemctl get-default 
multi-user.target

------ OR --------
# Work for neither
$ sudo systemctl status multi-user.target 
● multi-user.target - Multi-User System
   Loaded: loaded (/usr/lib/systemd/system/multi-user.target; static; vendor preset: disabled)
   Active: active since Wed 2016-03-09 15:57:02 AEDT; 1 day 1h ago
     Docs: man:systemd.special(7)
$ sudo systemctl get-default 
multi-user.target
$ sudo systemctl preset-all
$sudo systemctl get-default 
multi-user.target
$ echo "enable multi-user.target" >> sudo tee -a /etc/systemd/system-preset/01-target.preset
$ sudo rm /etc/systemd/system/default.target
$ sudo systemctl daemon-reload
$ sudo systemctl status multi-user.target 
● multi-user.target - Multi-User System
   Loaded: loaded (/usr/lib/systemd/system/multi-user.target; static; vendor preset: enabled)
   Active: active since Wed 2016-03-09 15:57:02 AEDT; 1 day 1h ago
     Docs: man:systemd.special(7)
$ sudo systemctl preset-all
$ sudo systemctl get-default 
graphical.target


Additional info:
Possibly if it works for both a default preset policy should be added to:
/usr/lib/systemd/system-preset/90-default.preset

Comment 3 Aaron Howell 2016-11-28 05:24:24 UTC
I just realised the "works for neither" section had a typo - the last lines of output should be:
$ sudo systemctl get-default 
multi-user.target

Comment 9 Jan Synacek 2018-05-24 11:54:44 UTC
https://github.com/systemd/systemd/issues/9078

Comment 10 Jan Synacek 2018-06-13 11:42:07 UTC
Ok, so this actually works as it should. See the uspstream issue for details.

To sum up:
The 'preset-all' command removes default.target, even if it's in the configuration file, because "default.target" is not an actual name of a unit file. Also, when "multi-user.target" or "graphical.target" is specified in the configuration, it is not enabled as it doesn't have an Install section (see https://github.com/systemd/systemd/commit/02ebe178a2bd6b2448d4fbfa4a1f7fa98e9e82b1 for the reasoning).