• Jenkins服务开机自启动


    最近因为护网行动,每天都要对服务器进行开、关机操作。为了省事儿,对Jenkins服务进行开机自动启动服务改造。实现如下:

    1. 通过chkconfig --list命令列出系统中已安装的服务及其启动状态

    复制代码
    [root@qy-ggyf-zyl-32 ~]# chkconfig --list
    
    Note: This output shows SysV services only and does not include native
          systemd services. SysV configuration data might be overridden by native
          systemd configuration.
    
          If you want to list systemd services use 'systemctl list-unit-files'.
          To see services enabled on particular target use
          'systemctl list-dependencies [target]'.
    
    celeryd-Server_soinnx   0:off   1:off   2:on    3:on    4:on    5:on    6:off
    netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
    network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@qy-ggyf-zyl-32 ~]#
    复制代码

    2. 创建启动脚本

       在/etc/init.d/目录下,创建Jenkins启动脚本

    vim jenkins_startup.sh

      脚本内容如下:

    复制代码
    #!/bin/bash
    #chkconfig:2345 80 90
    #decription:启动Jenkins
    
    nohup /usr/local/jdk-11.0.17/bin/java -jar /usr/local/jenkins.war &
    #请将/usr/local/jdk-11.0.17/bin/java和usr/local/jenkins.war替换为实际的路径。
    复制代码

     3. 编辑完脚本后对脚本进行赋权

     chmod +x jenkins_startup.sh

    4. 将脚本添加进清单

    chkconfig --add jenkins_startup.sh

    5. 添加完毕后查看清单 

    复制代码
    [root@qy-ggyf-zyl-32 ~]# chkconfig --list
    
    Note: This output shows SysV services only and does not include native
          systemd services. SysV configuration data might be overridden by native
          systemd configuration.
    
          If you want to list systemd services use 'systemctl list-unit-files'.
          To see services enabled on particular target use
          'systemctl list-dependencies [target]'.
    
    celeryd-Server_soinnx   0:off   1:off   2:on    3:on    4:on    5:on    6:off
    jenkins_startup.sh      0:off   1:off   2:on    3:on    4:on    5:on    6:off
    netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
    network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@qy-ggyf-zyl-32 ~]#
    复制代码

    至此,完成了Jenkins随操作系统启动自启服务的操作,也可以使用service jenkins_startup.sh start/stop/restart命令来重启服务。


    问题记录及调试过程:

    ① 最初的脚本内容:

    #!/bin/bash
    #chkconfig:2345 80 90
    #decription:启动Jenkins
    
    nohup java -jar /usr/local/jenkins.war &

    ② Java设置了环境变量,但是开机启动Jenkins服务失败,手动调试也出现报错,如下:

    [root@qy-ggyf-zyl-32 init.d]# service jenkins_startup.sh restart
    [root@qy-ggyf-zyl-32 init.d]# nohup: appending output to 'nohup.out'
    nohup: failed to run command 'java': No such file or directory

    ③ 查看Java路径:

    [root@qy-ggyf-zyl-32 init.d]# which java
    /usr/local/jdk-11.0.17/bin/java

    ④ 将jenkins_startup.sh的Java路径改写为绝对路径:/usr/local/jdk-11.0.17/bin/java,再次执行service jenkins_startup.sh restart,服务重启成功,Jenkins服务也实现了开机自启动。

    [root@qy-ggyf-zyl-32 init.d]# service jenkins_startup.sh restart
    [root@qy-ggyf-zyl-32 init.d]# nohup: appending output to 'nohup.out'

     

  • 相关阅读:
    如何修复和解决 IP 地址冲突
    高等院校教师资格证考试怎么考,要什么条件?
    使用springcloud-seata解决分布式事务问题-2PC模式
    基于SpringBoot的网上超市系统
    目标检测YOLO实战应用案例100讲-面向路边停车场景的目标检测(中)
    大家看看立体几何计算问题。
    一文带你搞懂sklearn.metrics混淆矩阵
    我试图扯掉这条 SQL 的底裤。只能扯一点点,不能扯多了
    0097 弗洛伊德算法,马踏棋盘算法
    Base64结合密码学x509编码和PKCS#8编码
  • 原文地址:https://www.cnblogs.com/n00dle/p/17619828.html