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.
Since you are using CentOS 7.x, create a Unit.
vim /usr/lib/systemd/system/miner.service as
root and put the following contents:
[Unit] Description=miner [Service] ExecStart=/path/to/miner [Install] WantedBy=multi-user.target
You could add
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.
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
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 :
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