Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: How to "load" a systemd Unit file?

  1. #1
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,107
    Blog Entries
    2

    Default How to "load" a systemd Unit file?

    Came across something curious I hadn't noticed before...

    First, I found that "systemctl -a" doesn't actually display "all" Units on the system - It only displays all "loaded" Unit files.

    Objective:
    Install ssh server on 13.1.

    Procedure:
    If needed, but most likely already installed
    Code:
    zypper in openssh
    Now, how to start the service? I started looking for the Unit file...
    The following does not return the Unit file
    Code:
    systemctl -a | grep ssh
    But the following does
    Code:
    systemctl list-unit-files | grep ssh
    You can't enable much less start an unloaded Unit file, I couldn't find a way to activate the ssh Unit file except by the following way...
    Exhausting everything I could think of and not finding anything in documentation I read(I may have missed something), I invoked ssh the "old, SystemV" way...
    Code:
    # /etc/init.d/bin/ssh start
    Which did the trick. Now you can view the running ssh service
    Code:
    systemctl status ssh
    I'm sure there should be a way to "load" the ssh Unit file without a SystemV init start command, looking for the right command
    BTW - I think it's really cool how the openSUSE folks have made ssh server installation so quick and painless... automating tasks like server key generation and installation, and configuring the ssh config file to automatically support most likely desired features like X11 forwarding, binding to any/all network interfaces. Kudos to the people who did that.

    TSU

  2. #2

    Default AW: How to "load" a systemd Unit file?

    Quote Originally Posted by tsu2 View Post
    First, I found that "systemctl -a" doesn't actually display "all" Units on the system - It only displays all "loaded" Unit files.
    Unit files are "loaded" on boot.
    To make systemd rescan which ones are installed, run:
    Code:
    systemctl daemon-reload
    But installing the "openssh" package should do that automatically.
    It runs "systemctl daemon-reload" in the postinstall script, at least in the 13.1 package.

    You can't enable much less start an unloaded Unit file
    No. And you cannot load it either.

    Exhausting everything I could think of and not finding anything in documentation I read(I may have missed something), I invoked ssh the "old, SystemV" way...
    Code:
    # /etc/init.d/bin/ssh start
    Which did the trick.
    I doubt that.
    Shouldn't it rather be "/etc/init.d/sshd start"?
    At least that's where it is installed on _my_ 13.1 system.
    There is _no_ /etc/init.d/bin/ssh .

    Now you can view the running ssh service
    Code:
    systemctl status ssh
    No. The service is called "sshd", at least on _my_ system.
    This should show its status therefore:
    Code:
    systemctl status sshd
    I'm sure there should be a way to "load" the ssh Unit file without a SystemV init start command, looking for the right command
    If you want to start the ssh service, run:
    systemctl start sshd
    To enable starting it at boot:
    systemctl enable sshd
    Or just use YaST->System->Services Manager for all of that.
    Last edited by wolfi323; 21-Aug-2014 at 13:43.

  3. #3
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,107
    Blog Entries
    2

    Default Re: How to "load" a systemd Unit file?

    1. Yes, the actual ssh init file is /etc/init.d/sshd

    2. No, apparently this is new to me that openSUSE does not necessarily load all installed Unit files on boot. And that's the crux, up until now I thought that "systemctl -a" should list every Unit file on the system no matter the state... But after my discovery that it doesn't I read the description of "systemctl -a" more closely and there in the "Help it clearly says that there can be a difference between "loaded" Unit files and Unit files simply on the system which I then described in my post (systemct list-unit-files).

    The point is, by default the sshd Unit file exists on the system but is "unloaded" so you <cannot> "systemctl start" or "systemctl enable" the Unit file. And, you can reboot the system all you want but by default it will not "load."

    Not believing what I was looking at first, I then inspected and verified this on 4 existing VM guests I've built over time and this exists on all of them.

    TSU

  4. #4
    Join Date
    Jun 2008
    Location
    Auckland, NZ
    Posts
    20,260
    Blog Entries
    1

    Default Re: How to "load" a systemd Unit file?

    The actual relevant service is sshd.service, and doing
    Code:
    rpm -ql openssh
    would have listed the corresponding service file
    Code:
    /usr/lib/systemd/system/sshd.service
    with the status being reported by
    Code:
    systemctl status sshd
    Quote Originally Posted by tsu2 View Post
    1. Yes, the actual ssh init file is /etc/init.d/sshd

    2. No, apparently this is new to me that openSUSE does not necessarily load all installed Unit files on boot. And that's the crux, up until now I thought that "systemctl -a" should list every Unit file on the system no matter the state...
    Well it's the service that you should be interested in, and the full list can be got from
    Code:
    systemctl list-unit-files
    The point is, by default the sshd Unit file exists on the system but is "unloaded" so you <cannot> "systemctl start" or "systemctl enable" the Unit file. And, you can reboot the system all you want but by default it will not "load."
    Why are you surprised about that? Again, it's the (systemd) service that you want to enable - in this case 'sshd.service'.

  5. #5

    Default Re: How to "load" a systemd Unit file?

    And in addition:
    "systemctl -a" does show the sshd.service: (at least on _my_ 13.1 system )
    Code:
    # systemctl -a |grep ssh
    sshd.service                   loaded active   running   OpenSSH Daemon
    If you still think your sshd.service is not loaded, please post the output of:
    Code:
    systemctl status sshd
    Last edited by wolfi323; 22-Aug-2014 at 02:17.

  6. #6
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,107
    Blog Entries
    2

    Default Re: How to "load" a systemd Unit file?

    Quote Originally Posted by deano_ferrari View Post
    The actual relevant service is sshd.service, and doing
    Code:
    rpm -ql openssh
    would have listed the corresponding service file
    Code:
    /usr/lib/systemd/system/sshd.service
    with the status being reported by
    Code:
    systemctl status sshd


    Well it's the service that you should be interested in, and the full list can be got from
    Code:
    systemctl list-unit-files


    Why are you surprised about that? Again, it's the (systemd) service that you want to enable - in this case 'sshd.service'.
    If you run "systemctl status sshd.service" in the exact order you describe, you will see the error
    "Unit file not found"

    As I'm describing, the Unit file has to be loaded before you can execute any systemd commands against it.

    I encourage anyone to verify for yourself what I've described...
    If anyone is running virtualization and has a ton of little used specific purpose openSUSE Guests created over time like I do, you can verify all this in a few minutes, every one will exhibit what I described.

    Otherwise, unless your current physical machine hasn't had the ssh service started before you won't be able to see this on your current machine.

    TSU

  7. #7
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,107
    Blog Entries
    2

    Default Re: How to "load" a systemd Unit file?

    Quote Originally Posted by wolfi323 View Post
    And in addition:
    "systemctl -a" does show the sshd.service: (at least on _my_ 13.1 system )
    Code:
    # systemctl -a |grep ssh
    sshd.service                   loaded active   running   OpenSSH Daemon
    If you still think your sshd.service is not loaded, please post the output of:
    Code:
    systemctl status sshd
    Only if your system has run the sshd service sometime in the past.
    Can you say you are sure you've <never> run the sshd service before, ever?

    TSU

  8. #8

    Default AW: Re: How to "load" a systemd Unit file?

    Quote Originally Posted by tsu2 View Post
    If you run "systemctl status sshd.service" in the exact order you describe, you will see the error
    "Unit file not found"
    No:
    Code:
    :~> systemctl status sshd.service
    sshd.service - OpenSSH Daemon
       Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
       Active: active (running) since Fre 2014-08-22 10:08:59 CEST; 6h ago
     Main PID: 935 (sshd)
       CGroup: /system.slice/sshd.service
               └─935 /usr/sbin/sshd -D
    And I never loaded anything manually.

    As I'm describing, the Unit file has to be loaded before you can execute any systemd commands against it.
    Again, it is loaded _on boot_.

    And also again, if it's different for you, please post the actual output of "systemctl status sshd.service" to prove it and so that people are able to help you.
    Last edited by wolfi323; 22-Aug-2014 at 07:27.

  9. #9

    Default AW: Re: How to "load" a systemd Unit file?

    Quote Originally Posted by tsu2 View Post
    Only if your system has run the sshd service sometime in the past.
    Can you say you are sure you've <never> run the sshd service before, ever?
    No, of course not. It is _enabled_ here, so it is started (not "run") automatically during boot.

    But how could I have ever enabled it, if it has to be "loaded" or "run" first as you claim. I never did that. And yes, I am sure about that.

    (PS: no, you do not "run" service files... )

    And another time: where's your output of "systemctl status sshd.service"?
    Last edited by wolfi323; 22-Aug-2014 at 07:32.

  10. #10
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,107
    Blog Entries
    2

    Default Re: How to "load" a systemd Unit file?

    Ok,
    Figured out the likely issue, my User error.

    I was trying to get the status of "ssh" instead of "sshd"
    Still, am a bit mystified that the followed doesn't return a result until the sshd is run at least once
    Code:
    systemctl -a | grep ssh
    The above of course should have returned any "ssh" and "sshd" results, but returns nothing at first.
    After running at least once, then it returns the ssd.service

    TSU

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •