Service File Location

we can find many service in linux.

Let’s take a look at Nginx.service

$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-03-31 12:50:17 UTC; 32min ago
 Main PID: 2839 (nginx)
   CGroup: /system.slice/nginx.service
           ├─2839 nginx: master process /usr/sbin/nginx
           └─2840 nginx: worker process

and if we type such command like this

$ sudo systemctl enable nginx
Created symlink from 
/etc/systemd/system/ to 

A symbolic link will be created.

Put Your Service File Here

here is where you should write service


then use the following command

$ sudo systemctl enable service-name

Service File Layout

here is nginx service file.

Description=The nginx HTTP and reverse proxy server

# Nginx will fail to start if /run/ already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
ExecStartPre=/usr/bin/rm -f /run/
ExecStartPre=/usr/sbin/nginx -t
ExecReload=/bin/kill -s HUP $MAINPID


Write Your Service File

this is just a little complex.
here is a simple one.

Description=this is a description
After=you can copy from nginx.service

ExecStart=/usr/bin/something /home/your-script

  • Type <- at most time simple is enough, sometimes you may need a forking1

  • Environment <- this is something you may need

  • Restart <- the best thing I like, your service will never down

  • <- this is for “enable”, which means command line use is simple output2


Write a Original Service File, and put it into


then just start & enable it via systemctl.

How To Configure a Linux Service to Start Automatically After a Crash or Reboot – Part 1: Practical Examples
How to Auto-start Services on Boot in Linux?
How to set up proper start/stop services
What is the difference between “systemctl start” and “systemctl enable”?
Creating Systemd Service Files
what is the CentOS equivalent of /var/log/syslog (on Ubuntu)?
sudo service status includes bad;
Run node.js service with systemd
How to Install Desktop Environments on CentOS 7
Install MATE or XFCE on CentOS 7
How To Install Xfce GUI In CentOS 7 Linux
man page: systemd.service — Service unit configuration
man page: systemd.unit — Unit configuration

Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)