Results 1 to 5 of 5
Hello,
I have a VPS running Fedora..
I run a game server and to start the server I exec an .sh file:
cd /home/game
sh server.sh
Is there a way ...
- 01-06-2012 #1Just Joined!
- Join Date
- Jan 2012
- Posts
- 2
Start script on boot
Hello,
I have a VPS running Fedora..
I run a game server and to start the server I exec an .sh file:
cd /home/game
sh server.sh
Is there a way to have it start automatically on boot in case the server is restarted?
Thanks
- 01-06-2012 #2
In case you still have an older fedora (<15) with SysVinit, this page should help
Packaging:SysVInitScript - FedoraProject
For fedora 15/16, SysVInitscripts can be used, but a better approach is to write a native systemd initscript
freedesktop.org - Software/systemd
Also:
The clean way would be to package the game server -including its libs, documentation, config, init scripts into an rpm,
because then there are no unmanaged bits and pieces lying around on the server.
How to create an RPM package - FedoraProjectYou must always face the curtain with a bow.
- 01-06-2012 #3Just Joined!
- Join Date
- Jan 2012
- Posts
- 2
Thanks, but I'm kinda new to Linux and those pages seem a bit complicated. Is there a simple way to make the server exec the .sh file on boot?
BTW, I'm on Fedora 14.
- 01-06-2012 #4
Well, there is the file /etc/rc.local which will be executed after all other initscripts.
You could place your commands here, and probably prefix them with a "su", if that game server runs with another user than root (it should)
Other than that: A sysvinitscript is not that complicted. Just well documented
Look at the template and read the description. Then it should become clear.You must always face the curtain with a bow.
- 01-07-2012 #5Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
You might want to run it in screen, it is run in the background and allows you to reconnect to it later to send commands to it, monitor, restart it. etc.
First make your script executable:
then run your script in a screen:Code:chmod +x /home/game/server.sh
you can see running screens with:Code:screen -S GameScreen -dm "/home/game/server.sh"
then attach to a running screen by taking the PID from the above command with:Code:screen -ls
Code:screen -r $PID
Initialization scripts for Fedora 14 (and previous versions) are pretty straight forward. You basically need:
1. chkconfig and description lines
2. start() and stop() functions that control starting / stopping your prog
3. case statement that processes required command line args
here's a crude example:
Then put it in the /etc/init.d/ directory, (e.g. /etc/init.d/myscript).Code:#!/bin/bash # chkconfig: 35 10 90 # description: blah # source function library . /etc/init.d/functions start() { action $"Starting blah: " /bin/your/prog } stop() { action $"Stopping blah: " kill -9 $(pidof yourprog) } case $1 in start) start ;; stop) stop ;; restart) stop; sleep 1; start ;; *) echo $"Usage: $0 {start|stop|restart}" esac
Make it executable:
Then run chkconfig on it to add the runlevels defined at the top of the script (3 and 5 in this case):Code:chmod +x /etc/init.d/myscript
Now that script will run in runlevels 3 and 5 upon reboot.Code:chkconfig --add myscript


Reply With Quote