How to Create and Run New Service Units in Systemd Using Shell Script

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ioannis Koustoudis

Ioannis Koustoudis is a LFCS­ Linux sysadmin from Kavala, Greece. He works for the ministry of education and supports almost 200 school units in their infrastructure. If he is not in front of a computer screen, he plays music (he is a multi­-instrumentalist) or take care of his two lovely kids.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

14 Responses

  1. princeofHack says:

    it’s wrong

    you MUST use /bin/bash /path/

  2. unnobt says:

    I created a systemd service. But it ask for password every time to start? How to make it run without sudo(ing)?

  3. ksotya says:

    My script doesnt’t start on boot, it starts only after maually typing systemctl start

  4. jagkd705 says:

    What happens when you issue the command?:

    systemctl stop connection.service

    Do you need to supply a stop script definition somewhere or does it just ignore if no stop script is defined?

    • Geert V. says:

      No, it simply stops the service. systemd is taking care of that for you. Note that the service is only stopped for the current session. Once you reboot, the service will be started again (you stopped the service, you didn’t disable it…)

  5. Bruno Silveira says:

    That was an amazing article, very well written and well explained, CONGRATS!
    You should continue writing articles like this one Ioannis, you are really good at it!

  6. Dan St-Andre says:

    I’d love to see a similar article about (1)mounting file systems at boot time, and (2)mounting external drives and media. Specifically, how to alter the default, automatic mount point.

  7. md says:

    What you outline in this article wont work until you run ‘systemctl daemon-reload’. This needs to be done when you add or change unit files.

    • Geert V. says:

      or you reboot. systemd daemon-reload is only needed when you instantaneously want to start the service (which is indeed most of the time what you want…)

  8. Daniel says:

    Could have shared it.. but you spelled systemd wrong in the title. It should not have a capital “D”. You could also have executed a command instead of running a script. It is a good example though.

    • Dan St-Andre says:

      Over the years, I’ve found that wrapping commands with scripts helps make things more maintainable. AND you can do things before and after your command if that is ever needed or wanted.

  9. Fer Nando says:

    Very useful!!!! Thanks so much!!!

  10. Jalal Hajigholamali says:

    Very useful and interesting article,
    Thanks a lot

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.