This certainly "works" (for some value of "works"), but it isn't the right way to start a server. CentOS 6 is still using upstart
in SysVinit compatility mode, and my Fedora 18 here runs systemd, so the following is from memory. Check your system, look around! Don't trust a colored square on the Internet...
Check /etc/init.d
, you will find the scripts that start all services on the machine there. See if there is as simple (short, ls(1)
helps) script for handling a network service, copy that to /etc/init.d/yourservice
, adjust the precedences (want to start latest and stop earliest), the runlevels in which the service is to be active, and the description in the header (the commented section at the beginning); read, understand, and modify to handle your service. Then use chkconfig(8)
to activate it and check if it is correctly configured, and try starting/stopping/restarting it (service start yourservice
, etc).
Check the documentation on startup/shutdown, this is a more detailed discussion of creating a new service from scratch, while you'll find a simple template here.