When I boot my CentOS box, the httpd service starts automatically. How do I make a custom service that does the same thing? I have a program I use for mining, and I don't want to need to run ./miner every time I boot the machine.

  • what version of CentOS are you using?
    – user34720
    May 31, 2017 at 18:06
  • I'm using CentOs 7.1 server.
    – Rei
    Jun 1, 2017 at 3:07
  • Are you sure that your miner program doesn't already have a script in /etc/init.d/ ?
    – M4rty
    Jun 1, 2017 at 9:46
  • 1
    Centos 7.1 -> systemd
    – user34720
    Jun 1, 2017 at 10:33

3 Answers 3


Since you are using CentOS 7.x, create a Unit. vim /usr/lib/systemd/system/miner.service as root and put the following contents:




You could add ExecStop= and ExecReload= options if there are specific arguments used to close or reload services.

After that, you just need to systemctl enable miner.service to make it start on each boot.

Related Stuff:

  • On my CentOS 7 box, I got a "command not found" when running "systemd enable miner.service". So I had to run "systemctl enable miner.service" instead.
    – Dave
    May 7, 2018 at 19:49
  • systemctl. My fault. Fixing it :)
    – user34720
    May 7, 2018 at 20:19
  • 1
    PSA: If, like me, you Googled your way here looking for how to do this in CentOS 6, you'll notice you don't have the systemd folder. What you want is the chkconfig tool, mentioned in M4rty's answer and further explained here: geekflare.com/how-to-auto-start-services-on-boot-in-linux Oct 9, 2018 at 17:41
  • @JustinMorgan, that's right. CentOS 6 does not use systemd as init or service manager system. One quick hack to it would be start this software using the /etc/rc.local script instead of creating a service start script...
    – user34720
    Oct 10, 2018 at 10:46

Depending on the miner program provider you might have the associated service already declared.

On centOS you can check :

# chkconfig --list 

and if you see your program you can tell the system to run it automaticly at boot time

# chkconfig postgresql on

If you don't find any result you can create your own dummy script using a template for example :

How do I create a service for a shell script so I can start and stop it like a daemon?

then put it in /etc/init.d/ and chmod +x it

You should be able to manage you miner application as a service with all the advantages that comes with it


If you just need to run the command on boot, trying to make an actual service isn't really required. The simplest thing to do is to drop . /path/to/miner in /etc/rc.d/rc.local. This file is a script that is run on every boot (and make sure rc.local is executable), so your command will run when the server starts up.

If you need it to actually be handled as a service though, the best way to do that will depend on whether you're using CentOS 7 or 5/6.

edit: forgot to mention, this will be executed as root, so if you need it run as a non-root user, use instead su - username -c /path/to/miner


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .