centos7 - tomcat 系统服务 (ansible-playbook 自动成功 第一版 未设置 command_warnings=True )

---------------------------------------手动设置tomcat为系统服务

一 在tomcat的bin目录下新建setenv.sh

CATALINA_PID="$CATALINA_BASE/tomcat.pid"

 

二 在tomcat所在目录下新建tomcat.pid文件

touch /opt/tomcat7/tomcat.pid

三 在/lib/systemd/system ( /usr/lib/systemd/system )目录下新建tomcat.service文件

 

[Unit]
Description=tomcat7
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking

# Environment=“JAVA_HOME=/opt/jdk1.8.0_152” # Environment对应jdk的安装目录 可以echo $JAVA_HOME 查看

PIDFile=/opt/tomcat7/tomcat.pid #PIDFile就是刚刚设置的在catalina.sh中设置的CATALINA_PID
ExecStart=/opt/tomcat7/bin/startup.sh #注意对应tomcat的安装目录
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

四 执行以下命令使配置生效

systemctl daemon-reload

 

五 systemctl相关命令

 

# 设置开机自启动
systemctl enable tomcat.service

# 停止开机自启动
systemctl disable tomcat.service

# 启动tomcat服务
systemctl start tomcat.service

# 停止tomcat服务
systemctl stop tomcat.service

# 重新启动服务
systemctl restart tomcat.service

# 查看服务当前状态
systemctl status tomcat.service

# 查看所有已启动的服务
systemctl list-units --type=service

 

 

-----  -----ansible-playbook 版本  自动安装tomcatl 并设置tomcat为系统服务   

# tomcat 源码安装  版本为 apache-tomcat-8.5.60.zip

---
- name: install tm8 package
  hosts: test133
  remote_user : root
  vars :
          #touch_file : setenv.sh
          path : /usr/local/hml-dzbd-server/

  tasks:
  
  #  - name: stop hml-dzbd-service
  #   service: name=hml-dzbd-server state=stopped enabled=yes

    - name: copy tomcat8 to server
      copy: src="/root/apache-tomcat-8.5.60.zip" dest="~/apache-tomcat-8.5.60.zip"

    - name: make sure installed unzip pkg
      yum:
        name: unzip
        state: latest

    - name: unzip tomcat8.zip file
      shell: unzip -n ~/apache-tomcat-8.5.60.zip -d /usr/local
    
    - name: del hml-dzbd-server soft link file 
      file:
        path: /usr/local/hml-dzbd-server
        state: absent

    - name: create tomcat-8 soft link
      command: ln -s /usr/local/apache-tomcat-8.5.60 /usr/local/hml-dzbd-server
      when: 

    - name: copy tomcat catalina.sh conf file
      template: src=catalina.sh dest=/usr/local/hml-dzbd-server/bin/catalina.sh

    #- name: copy setenv.sh
    #  template: src=setenv.sh dest=/usr/local/hml-dzbd-server/bin/setenv.sh

    - name: Make tomcat bin dir's files has execute acl
      file:
        path: /usr/local/hml-dzbd-server/bin
        mode: 0755
        recurse: yes

    #- name: copy setenv.sh
    #  template: src=setenv.sh dest=/usr/local/hml-dzbd-server/bin/setenv.sh
   
    #- name: create tomcat Pid file
      #template: src=tomcat.pid dest=/usr/local/hml-dzbd-server/tomcat.pid
      #file: name=/usr/local/hml-dzbd-server/tomcat.pid state=touch
    - name : touch setenv/sh
      shell: touch {{ path }}/bin/setenv.sh
    - name: touch tomcat Pid 
      shell: touch {{ path }}/tomcat.pid
    - name: echo file setenv.sh
      shell: echo 'CATALINA_PID="$CATALINA_BASE/tomcat.pid"' > {{ path }}/bin/setenv.sh
    - name: copy template hml-dzbd-server
      template: src=hml-dzbd-server.service dest=/usr/lib/systemd/system/hml-dzbd-server.service
    
    - name: finish tomct system servie setup!!!
      shell: systemctl daemon-reload

    - name: start up hml-dzbd-service
      service: name=hml-dzbd-server state=started


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值