I currently own a VPS with Centos7 installed. I also have a programmed 'Steambot' that I would like to put onto the VPS and have it automatically run at all times while the VPS is online. I'm not sure how to do this and researched and noticed from a post on the /r/SteamBot subreddit that mono was needed on the VPS to accomplish this. Not sure rather or not that is true or not which brought me here.
2 Answers
First get it to run "manually". If you haven't already, install epel and mono, and get the bot working. You'll basically need to write something that'll start the command, and keep it running.
Write an init script to start it. Centos 7 uses systemd, which would let you do neat things like automatically restart. I've not dived into systemd myself but its well documented.
The method I normally use is supervisord. Its not system level. will restart things on failure, and has a optional webui
Your supervisord script is as simple as
command=command to run steambot
directory=directory you want to run steambot in
autostart=true
startretries=5
stderr_logfile=/var/log/supervisor/ttrss/ttrss.err.log
user=www-data
This logs errors, and You can add a line to log stdout for troubleshooting purposes.
- Add it to your crontab if its a non interactive application (else it gets trickier). @reboot will start it once when you reboot, but the other methods are better since they log and restart on error
-
-
I'm not familiar enough with it yet. It certainly would be the best option.– Journeyman Geek ♦Nov 2, 2015 at 6:07
The simplest thing is to write a systemd service. Systemd has a very large range of possibilities, and you did not specify what you desire, so that I will give you just a very simple script:
[Unit]
Description=Some comment here about what this does
After=network.target
[Service]
EnvironmentFile=-/path/to/flag/setting/file
ExecStart=/absolute/path/to/executable $FLAGS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
User=%i
Group=users
[Install]
WantedBy=multi-user.target
The $FLAGS variable should be set in the file /path/to/flag/setting/file
, if it is a complex choice, otherwise just delete this line and replace the one below with
ExecStart=/absolute/path/to/executable -i -f -d
or whichever flags you need. The above should be put into a file called [email protected]
. This way it can be called as
systemctl [email protected]
and the excutable will be run as user MyName. You should place the above file into /etc/systemd/user
,so that it is run as a user service, not a system service. The advantage of this is that any user can run it, not just root. You can always control it with systemctl --user
.
If instead you do not care about other users being able to run the service, use the line
User=MyName
save the file in myservice.service
, and control it without passing the argument, as systemctl myservice ...