Linux下,设置各种服务的开机自启动
2014-03-12 14:18
846 查看
首先,在Windows里,编写bash脚本,测试其中各命令都是可用的。我写的脚本(yl_services)如下:
其中,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开头,启动时会被执行到!
#!/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>&1 su - postgres -c "/usr/local/pgsql/bin/pg_ctl start" #nginx su - root -c "usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" #tomcat:desktop su - root -c "/home/desktop/apache-tomcat-7.0.42/bin/startup.sh" #desktop-server su - 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开头,启动时会被执行到!
相关文章推荐
- Linux将服务设置为开机自启动的方法小结
- 注册自定义的Jar包为Linux服务并设置为开机自启动
- linux设置服务开机自启动的三种方式
- Linux之设置服务为开机自启动
- Linux设置程序的开机自启动与Linux服务
- linux搭建redis服务设置开机自启动 service命令stop、start启动停止服务
- 设置 linux环境 tomcat 服务开机自启动
- Linux设置开机自启动服务
- linux设置开机服务自启动/关闭自启动 chkconfig命令
- Linux服务开机自启动设置
- Linux服务设置开机自启动,服务状态等。。。
- linux开机自启动设置,自定义开机启动模版,nginx开机自启动服务
- Linux中设置服务开机自启动的三种方式
- linux设置服务开机自启动的三种方式
- Linux中设置服务自启动的三种方式
- Linux中设置服务自启动的三种方式
- Linux如何设置服务自启动
- linux设置开机服务自动启动
- 配置Linux服务下mysql数据库服务开机自启动
- 使用Java Service Wrapper设置tomcat作为linux服务并且开机自动启动