How-to create your own systemd service files

Many Linux operating systems, like OpenSuse, Fedora are using Systemd daemon instead of Linux init based daemon (known as systemV). Systemd is meant to provide a better framework for expressing services’ dependencies, allow more work to be done in parallel (concurrently) at system startup, and to reduce shell overhead.

I use a script (I made it a service) which gets executed at system boot, this script/service search for certain conditions like network settings and if they are true it reset them with default configuration. Recently I have created a Fedora18 VM and tried to run this service on it but it failed. As Fedora 18 is Systemd based, I now have to configure the script/service to work with it.

Following are the steps which I have followed to create and configure systemd service file.

Note: Location of the script is /etc/init.d/

  1. Go to systemd directory i.e. /usr/lib/systemd/system/
  2. Create a new file with name “servicename.service“. In my case I have created file named “mycustomscript.service
  3. Add following content in the above file:

    Description=mycustomscript Deamon auditd.service[Service]


  4. Now reload the Systemd Daemon using command “systemctl daemon-reload“. This will notify systemd about new service.

    [root@localhost ~]# systemctl daemon-reload
    [root@localhost ~]#

  5. Test the service you have created by starting it “systemctl start mycustomscript“.

    [root@localhost ~]# systemctl start mycustomscript
    [root@localhost ~]#

  6. Now enable the service “systemctl start mycustomscript

    [root@localhost ~]# systemctl enable mycustomscript
    ln -s ‘/usr/lib/systemd/system/mycustomscript.service’ ‘/etc/systemd/system/’
    [root@localhost ~]#

  7. You can check and verify if the is service properly added in systemd or not using command “systemctl –all | grep mycustomscript

If you see your service in the list, bingo you have successfully created the service.

About: Mike

Milind Koyande loves to work on new technologies specially virtualization and troubleshoot server problems. I’m an avid photographer and love to spend my free time close to nature, trying to capture its glory on my camera.

2 thoughts on “How-to create your own systemd service files”

  1. Hi Milind..
    Nice post..I like your way to express the all steps in simple and easy to understand. Anybody can easily know these steps and implement it to generate our own system serviced files…keep it up..thanks..!!!

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