免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1225 | 回复: 0

[OS Liunx] How To Install Services on Linux [复制链接]

论坛徽章:
0
发表于 2010-01-10 22:12 |显示全部楼层

               
Allow me to give you a little introduction on the subject prior to theproper howto. The Linux boot process can be splitup in three steps:
Loading the kernelDevice detection and configurationGranting control to ‘init’The ‘init’ program is a daemon that spawns all other processes in thesystem. It is responsibe for loading the systemusing initialization scripts, which are usually found at /etc/init.d.There are two ways for init to operate, BSD andSystemV. Typically, Linux systems use SystemV, though there aredistributions like Arch Linux or Slackware that use BSD.
The runlevel is a number used to identify the mode in which thecomputer is. For example, a runlevel 0 would mean thatthe computer is halted, while changing the runlevel to 6 would makethe computer reboot. There are 7 runlevels.Runlevels from 1 to 5 usually differ in the programs that areautomatically started. Typically, runlevel 3 is used toboot in text-only mode, while runlevel 5 will start the X server andthe desktop environment.
For each runlevel, there is a folder named rcN.d (where N stands forthe runlevel number) which contains symbolic linksto the some of the scripts located at /etc/init.d.
When changing the runlevel, what the system does is:
Changing directory to /etc/rcN.d or /etc/rc.d/rcN.d (depends on thedistribution).All the scripts that begin with K are executed in alphabetical orderwith the argument ‘stop’. Usually there arenumbers after the K to be able to control the exact execution order.All the scripts that begin with S are executed in alphabetical orderwith the argument ‘start’. As before, numbers areused to sort the scripts before execution.If you want to learn more, you can find information about init and runlevels at:
http://en.wikipedia.org/wiki/Init
http://en.wikipedia.org/wiki/Runlevel
http://www.redhat.com/docs/manuals/linux/RHL-7.2-Manual/ref-guide/s1-init-boot-shutdown-init.html
http://linux.about.com/od/commands/l/blcmdl8_init.htm
Now lets get our hands dirty and learn how to make the BitNami stackservers start at boot time :) Bear into mind thatyou will need root privileges to do it.
- Debian-like distribution (Debian, Ubuntu, etc)
1. Copy the installdir/ctlscript.sh file to /etc/init.d . It isadvisable to rename this script to something more specific, like “bitnami-drupal”.
cp installdir/ctlscript.sh /etc/init.d/bitnami-drupal2. We will use rc-update.d to add the script to the desired runlevels.
update-rc.d -f bitnami-drupal start 80 2 3 4 5 . stop 30 0 1 6 .
As you can see, we define the priority (80 for start and 30 for stop) and the runlevels in which the script will be executed. The result of this command will be something like
Adding system startup for /etc/init.d/bitnami-drupal … /etc/rc0.d/K30bitnami-bitnami-drupal → ../init.d/drupal /etc/rc1.d/K30bitnami-bitnami-drupal → ../init.d/drupal /etc/rc6.d/K30bitnami-drupal → ../init.d/bitnami-drupal /etc/rc2.d/S80bitnami-drupal → ../init.d/bitnami-drupal /etc/rc3.d/S80bitnami-drupal → ../init.d/bitnami-drupal /etc/rc4.d/S80bitnami-drupal → ../init.d/bitnami-drupal /etc/rc5.d/S80bitnami-drupal → ../init.d/bitnami-drupalAnd that’s it, the servers will be loaded at boot time. To revertthe changes, just type
update-rc.d -f bitnami-drupal remove
- RedHat-like distribution (Red Hat, Fedora Core, CentOS, Suse, etc)
1. Copy the installdir/ctlscript.sh file to /etc/init.d . It isadvisable to rename this script to something more specific, like “bitnami-drupal”.
cp installdir/ctlscript.sh /etc/init.d/bitnami-drupal2. You have to modify the script a little bit to make it work atboot time. Just add the following lines at the beginning of the file
#!/bin/sh#
chkconfig: 2345 80 30description: BitNami ServiceThis means that the script will be executed in runlevels 2, 3, 4and 5, with priority 80 to start, and 30 to stop.
3. Now, you only need chkconfig to install the script as a service.
chkconfig —add bitnami-drupal
And you’re done. To revert the changes, we will use chkconfig again
chkconfig —delete bitnami-drupal
That’s all! If you have comments or suggestions, please post at thefollowing topic on the forums
http://bitnami.org/forums/forums/27/topics/344
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/90363/showart_2145106.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP