saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.12k stars 5.47k forks source link

Salt state to set system runlevel or target #46484

Open craigafinch opened 6 years ago

craigafinch commented 6 years ago

Description of Issue/Question

I want to write a Salt state that installs and enables a minimal X Windows GUI on a CentOS 7 system. I need a state to ensure that a specific systemd default target has been set for the system. An equivalent command is:

systemctl set-default graphical.target

I also can't find a state to manage the legacy System V runlevels. Does such a state exist? If so, I am requesting to improve the documentation, because I searched pretty extensively and couldn't find anything. If it does not exist, please consider this to be a feature request.

Versions Report

Salt Version:
           Salt: 2017.7.4

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.21.1
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.1
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.5 (default, Aug  4 2017, 00:39:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.4.1708 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-693.17.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.4.1708 Core
salt-minion 2017.7.4 (Nitrogen)
garethgreenaway commented 6 years ago

@craigafinch Thanks for the report. I would suggest taking a look at the systemd execution module, which you can call from state files. It is also possible to configure the runlevel of the system using the system module and the init function within that module, https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.system.html#salt.modules.system.init

craigafinch commented 6 years ago

@garethgreenaway Thank you for your reply. From what I can tell, neither of those modules will accomplish what I want. The systemd module only manages services, not targets. The init function in the system module sets the current runlevel of the target system. It doesn't set the default runlevel. For example, initcan force the system into a particular runlevel right now, but it can't configure the machine to go into that runlevel automatically on the next boot.

gbrayut commented 5 years ago

It would be nice to have the default target managed by the module, but for now the following should work for systemd init systems:

# Ensure default target is set to 'multi-user.target' (non-graphical). Change to 'graphical.target' if that is what you prefer
systemd_default_target:
  cmd.run:
    - name: systemctl set-default multi-user.target
    - unless: test `systemctl get-default` = 'multi-user.target'
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

bdrx312 commented 1 year ago

Please reopen. This appears to still be a valid issue. It would be useful to have a state to set the default and current target to be able to enable graphical.target for a desktop host for example.

OrangeDog commented 1 year ago

Are there service managers other than systemd and init.d/upstart that have a similar concept? I am wondering what a good cross-platform name would be for the functions.