首页 > 解决方案 > 服务器重新启动后在 Linux 中重新启动服务

问题描述

因此,今天我们的一个应用程序服务器由于某些问题而重新启动,重新启动后我们发现我们的应用程序服务没有运行。

我想创建一个脚本,它将在服务器重新启动后检查以下这些服务,如果发现停止则自动启动它们:

带有路径的第一个服务:/opt/bea/config/nm/nm-sdi-abc/beaNMctl.sh 

第二个服务 TOMCAT - 路径:/opt/apache/tomcat/bin --- 服务名称 startup.sh

抓住这里是第一个服务可以用我使用的普通 id 帐户启动。

但是第二个服务可以在登录到同一服务器和网络上的不同服务帐户后重新启动。如下所示:

[x201691@abc bin]$ su - apache

密码:

-bash-2.05b$ cd /

-bash-2.05b$ cd /opt/apache/tomcat/bin/

-bash-2.05b$ ./startup.sh

有人可以帮忙吗?

我们也不是root用户。

标签: linuxtomcatnodemanager

解决方案


Preferred approach when installing Tomcat in Linux is to make Tomcat as a service.

This will ensure your service is started after reboot

1. Create the service file with the following command:
    
touch /etc/systemd/system/tomcat.service

2. Assign the relevant rights to the file you created:

   chmod 664 /etc/systemd/system/tomcat.service

3. Paste the following content in the file while adapting it to your configuration:

       [Unit]

       Description=Application description/name

       After=syslog.target network.target

       [Service]

       Type=forking

       User=tomcat

        ExecStart=$CATALINA_HOME/bin/startup.sh

        ExecStop=/bin/kill -15 $MAINPID

        Install]

        WantedBy=multi-user.target


4. Reload the service daemon:
 systemctl daemon-reload

5. Start the service:
     systemctl start tomcat

6. To check status : 
    systemctl status tomcat

推荐阅读