Linux服务器端设置软件服务开机启动。(Linux服务器端设置 svn 服务开机启动)

关于 Linux的 服务自启,一般都知道 需要修改脚本文件 rc.local 。

如下,可以直接操做:

[root@byx-linux ~]# vim /etc/rc.d/rc.local

 这个脚本是使用者自定的开机启动程序,可以在里面添加想在系统启动之后执行的脚本或者脚本执行命令。

方法一:创建脚本文件(好维护)

(1.)在Linux服务器跟目录((/root路径下))创建一个脚本文件。(我要自启的程序,是svn  我就起名 svn )

[root@byx-linux ~]# touch svn.sh

(2) 进入脚本文件,开始编辑脚本。

[root@byx-linux ~]# vim svn.sh

     

(3)添加一下内容

 #!/bin/bash
 /usr/bin/svnserve -d -r  /opt/svn/repositories

这里有几点需要了解一下:

这里的 svnserve 服务路径保险起见,最好写绝对路径,因为启动的时候,环境变量也许没加载。

绝对路径怎么查?

[root@byx-linux ~]# which svnserve
(4)改该脚本的执行权限
[root@byx-linux ~]# chmod 777 svn.sh
(5)加入自动运行文件内:
[root@byx-linux ~]# vim /etc/rc.d/rc.local
在末尾添加脚本的路径:/root/svn.sh
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/root/svn.sh
~                                                                                                                                                             
~                                                                                                                                                             
"/etc/rc.d/rc.local" 16L, 551C  
(6)保存后,最好给rc.local 文件777权限:
[root@byx-linux ~]# chmod 777 rc.local
(7)重启Linux服务器,重启后查看后台进程是否有 svnver 服务:
[root@byx-linux ~]# ps -ef|grep svnserve
root       687     1  0 16:08 ?        00:00:00 /usr/bin/svnserve -d -r /home/svn/project/

第二种方法:直接填写脚本执行命令(很简单,直接把需要自启的软件服务执行命令 放到 rc.local 文件里面)

(1.)直接编辑 rc.local 文件:

[root@byx-linux ~]# vim /etc/rc.d/rc.local
在末尾添加需要自启的脚本路径:
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/bin/svnserve -d -r  /opt/svn/repositories
~                                                                                                                                                             
~                                                                                                                                                             
"/etc/rc.d/rc.local" 16L, 551C  
 
 
(2)保存后,最好给rc.local 文件777权限:
[root@byx-linux ~]# chmod 777 rc.local
(3)重启Linux服务器,重启后查看后台进程是否有 svnver 服务:
[root@byx-linux ~]# ps -ef|grep svnserve
root       687     1  0 16:08 ?        00:00:00 /usr/bin/svnserve -d -r /home/svn/project/
 
 
 
 
希望可以帮助到你。
 
by不言谢。
不要和别人比,要赢得是自己。(ง •̀_•́)ง
原文地址:https://www.cnblogs.com/byx1024/p/12346024.html