Linux下,设置各种服务的开机自启动

来源:互联网 发布:云计算的特点以为中心 编辑:程序博客网 时间:2024/04/29 05:29
首先,在Windows里,编写bash脚本,测试其中各命令都是可用的。我写的脚本(yl_services)如下:
#!/bin/bash#Start all kinds of services#mysql#/usr/local/mysql/bin/#start mysql#postgres#su - postgres -c "/usr/local/pgsql/bin/postmaster -D '/data/db/postgres' &" >>"/data/db/postgres/serverlog" 2>&1su - postgres -c "/usr/local/pgsql/bin/pg_ctl start"#nginxsu - root -c "usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf"#tomcat:desktopsu - root -c "/home/desktop/apache-tomcat-7.0.42/bin/startup.sh"#desktop-serversu - root -c "/home/desktop/desktop-server/bin/boot.sh start"

其中,mysql会自启动,postgres和nginx,tomcat,desktop-server等服务,用此脚本启动。

然后,将该脚本保存成Unix格式(Unix的换行符是0x0A,而Windows的回车换行符是0x0D0x0A);
然后,将它复制到Linux系统(/home),修改为可执行(chmod 777 /home/yl_services);
然后,用如下命令,将该脚本链接到启动目录(/etc/init.d)中,并链接到对应的运行等级目录中;
[root@localhost ~]# ln -s /home/yl_services  /etc/init.d/
[root@localhost ~]# ln -s /etc/init.d/yl_services /etc/rc2.d/S99ylServices
[root@localhost ~]# ln -s /etc/init.d/yl_services /etc/rc3.d/S99ylServices
注:rc2.d和rc3.d,分别对应运行等级的2和3;其下的链接以S开头,启动时会被执行到!

0 0