0

I have placed a systemd service file in usr/lib/systemd/system/testfile.service. Here is the service file:

[Unit]
Description=Test service

[Service]
Type=notify

ExecStart=/bin/dd.sh

ExecReload=/bin/kill -HUP $MAINPID

KillMode=process

Restart=on-failure

RestartSec=30s

[Install]

WantedBy=multi-user.target

I tried to start the service at boot time by trying these two ways

  1. Created a softlink for the file from /usr/lib/systemd/systemd to /etc/systemd/system/multi-user.target.wants (manually and by using systemctl enable command) and rebooted the system, testfile service started successfully at boot time .
  2. created a dependency in the existing up and running service file like After=testfile.service and Wants=testfile.service, then rebooted the system testfile service started successfully.

But when I place the file /usr/lib/systemd/system and without any 1 or 2 solution approach service is not started, I feel that placing the service file in /usr/lib/systemd/system/ is enough for any service to start automatically , without creating the softlinks to wants directory or creating the dependency with the other services.

Please let me know, how to start a service at boot time which is present in /usr/lib/systemd/system directory without 1 or 2 solution approaches?

I have also created preset files in usr/lib/systemd/system-preset/ to disable and enable few services, seems like those preset files were not executed , services which i have disabled in the preset file are still enabled after the boot up. Please let me know how to debug this issue.

0

You should store your custom unit files in /etc/systemd/system/. After you create them, you have to enable them with systemctl enable name, which creates necessary symlinks.

0

When you place a unit file in /usr/lib/systemd/system you are merely adding it to the library of units available on the system. But you haven't told the system to run it.

Normally you would then run systemctl enable myservice. This will effectively create the symlink that you did manually.

It's this link that tells the boot processes what units to start up at boot time.

If you're used to older forms of init then you can think of this as the equivalent of putting a file into /etc/init.d; until you add a link to /etc/rc3.d/S##myservice then it won't start at boot time.

Now there may be conditions where other services may depend on your service and that'll cause a start up, but if nothing depends on your service then you have to have the symlink created by systemctl enable.

  • Thanks for the response. I tried systemctl enable <service> and rebooted the system , service has started at bootime , but my question was to start the service without symlink (systemctl enable or manually creating the symlinks). But it seems like service is not started without any symlinks or dependacny with the other up and running services. – RAJESH DASARI Aug 16 '16 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.