Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,everyone:
I want to config a program(Helloworld for instance) as a service on fedora linux with that version 14,when I press the computor power button, and then start my linux system.When the system started I hope the program(Helloworld) started automatically too. I can use the service status、service restart、service stop
command to start or stop this service of mine.
I find some information and aritcle how to config it.They say use the inetd.conf file on etc folder,but i can not find this file on /etc.
Can you tell me how to config it,the more detailed, the more better!
Thank you everyone!
Posted

Ignore any articles talking about inetd, they aren't relevant to Fedora.
To configure a service you need to add a shell script in /etc/init.d/ that contains functions to start, stop and restart your program. See the documentation in
/usr/share/docs/initscripts-9.20.2/sysvinitfiles<br />
and man chkconfig
For additional questions, try the Fedora Forums[^]
 
Share this answer
 
You have a simple way of doing it.

You need to write a custom script that will manage the start/stop/restart of the service that is being added.

The skeleton of that script looks like this.

Bash
#!/bin/bash

ReturnVal=0

start()
{
     # Star the service. 
     echo "Service is being started..."
}

stop()
{
    # Stop the service here.
    echo "Service is being stopped..."
}

restart()
{
    echo "Service is being Restarted..."
    stop
    start
}


# Main Wrapper

case '$1' in 

start)
start
;;

stop)
stop
;;

restart)
restart
;;

*)
echo "Invalid Option related to the Service."
echo $"Usage: $0 {start|stop|restart}"

exit 1
esac

exit $ReturnVal


The above script template can be used to create a custom script that can be used to manage a new service.

After this script is created place the file under
/etc/init.d

Make sure the sctipt is working properly by executing the following commands

service start
service stop
service restart


This can then be added using the chkconfig command.

chkconfig -add scriptname
For adding this to the auto start during bootup you can use the option.
ntsysv
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900