0

I have a service I want to run right after my computer start.

The steps I've followed for it are as follows:

Create cv

  1. Create cv-init.service in /usr/lib/systemd/system
  2. Format the file as shown below
  3. sudo systemctl daemon-reload
  4. sudo systemctl start cv-init.service
  5. sudo systemctl enable cv-init.service

When I run the enable command for the first time, I get this response:

Created symlink /etc/systemd/system/multi-user.target.wants/cv-init.service -> /usr/lib/systemd/system/cv-init.service

If I run the enable commands again, I get no response, I have to delete the symlink in multi-user-target-wants before it shows again.

As many other cases I've read from people having trouble with it, if I manually execute the service, it works, and though enabling is successful, when I restart my computer, it does not execute.

Here is my service file:

[Unit]
Description=Initialize CV

[Service]
Type=oneshot
WorkingDirectory=/app/configuration/cv_init
ExecStart=/app/configuration/cv_init/startup_cv.sh

[Install]
WantedBy=multi-user.target

I think its important to say that startup_cv.sh is not a script that keeps the daemon active, it just runs some commands that reads some logs and take some other actions, if I run the .sh file manually it works as intended, I just can't seem to make it work automatically on startup.

I've also tried many things that seem to have worked for people asking this kind of question like placing my service in /etc/init.d or in /etc/systemd/system, also specifying WANTS and those kind of things on my service, but it still doesn't work, could anyone lend me a hand?

2
  • 1
    Please add your question the complete output of systemctl status cv-init.service. No sudo needed. Ensure your terminal window is wide enough to see all the output.
    – user535733
    Feb 26, 2021 at 17:07
  • 1
    Your comment actually helped me solve my problem, I didn't know the systemctl status logs could get cut off if the window wasn't wide enough, after I exported the output to a text file, I managed to see my service was trying to execute before docker service was ready, I just added the required after dependency and everything works fine now. Thanks!
    – Omaruchan
    Feb 26, 2021 at 17:40

1 Answer 1

2

So I found out the problem, my /app/configuration/cv_init/startup_cv.sh executes a docker command, and my service was trying to execute before docker was ready. I just added the required dependency and it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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