linux - 服务器重新启动后在 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用户。
解决方案
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
推荐阅读
- javascript - 当我的 React 和 Node 服务器不同(Firebase)时,我遇到 Passport 问题,但当它们相同时(Heroku)没有问题
- c# - 文本框和 Datagridview 组合然后发送到 Mysql C# VisualStudio 代码
- ruby-on-rails-5 - Rails - 以自身为条件的哈希合并
- sql - Oracle SQL 子字符串
- html - 移动到不同页面时页脚闪烁
- javascript - 将参数值从数据表按钮传递给函数
- javascript - 文档未在 React Native 中定义
- windows-10 - 适用于 linux (WSL) 的 Windows 子系统可以在虚拟桌面中运行吗?
- python - TimeDistributed 与 LSTM 在关键字检测器中
- python - 根据 Pandas 中不同行的其他列中的值比较,将值应用于列