[Linux] Use commands under linux to modify the contents of a file in the jar package and re-run the jar program

Use commands under linux to modify the contents of a file in the jar package and re-run the jar program

1. Background description

Requirement: It is found that the log level configuration of the configuration file in the online iotp-irsb-server-v1.0.0.2.jar package is wrong, and the log level configuration of the application-prod.yml file in the jar package needs to be modified online. After the modification is completed And restart the jar package.

Two, vi command editing

Enter the directory where the jar package is located, and use the vi command to open the file list in the jar package.

1、vi iotp-irsb-server-V1.0.0.2.jar

vi iotp-irsb-server-V1.0.0.2.jar

As shown in the figure below:
insert image description here
2. In the file list interface that pops up after vi, select the file according to the cursor and press Enter.

  • After vi, enter / and then enter the content to be filtered to filter.
  • For example, enter /yml to quickly locate yml, click Enter, and then select the file according to the cursor . After locating the corresponding file, press Enter again to enter the file content modification interface.
/yml

As shown below:
insert image description here

3. Modify and save the content

  • After entering the file editing page, it is only a read-only file at this time. After entering the letter i, the read-only file will become an editable file, and then the content can be edited.
  • After modifying the content, press the esc key to exit editing, enter :wq to save the content, and return to the file selection list interface.

insert image description here

4. Finally, enter a colon and q! to complete the exit. So far, the contents of the files in the jar package have been modified.

insert image description here

3. Start the program

At this time, the program is still running. Under normal circumstances, you need to kill the process first, and then use the command to start it.

Tips: This kind of startup jar command usually has a startup script. After modifying the content at this time, you may only need to start the script to restart successfully.

Proceed as follows:

1. Find the process of the program, ps -ef |grep java

ps -ef |grep java

ps: Display a process
-A: Display all programs.
-e: The effect of this parameter is the same as specifying the "A" parameter.
-f: Display UID, PPIP, C and STIME fields. The grep command is to search, and the | in the middle is the pipeline command, which means that the ps command and grep are executed at the same time

This command means to display all java processes.

2. Kill this process, kill[parameter][process number]

kill -9 4394

kill is to send a signal to a process id. The signal sent by default is SIGTERM, and
the signal sent by kill -9 is SIGKILL, which is exit. The exit signal will not be blocked by the system, so kill -9 can kill the process smoothly. Of course, you can also use kill to send other signals to the process.

3. Start the jar program, nohup java -jar jar package name

nohup java -jar iotp-irsb-server-V1.0.0.2.jar

Supplement:
(1) CTRL+Z suspends the process and puts it in the background
(2) jobs displays the currently suspended process
(3) bg %N makes the Nth task run in the background (there is a space before %)
(4) fg %N Make the Nth task run in the foreground

4. Expansion – startup script

Modify the command and then use it as a startup script. For example, the name of this script is: autostart.sh, and the contents are the following commands:

#!/bin/sh
ps -ef | grep iotp-irsb-server | grep -v grep | awk '{print $2}' |xargs kill -9
cd /home/admin/web/iotp_irsb/app && (nohup java -jar -Dspring.profiles.active=prod iotp-irsb-server-V1.0.0.2.jar  -Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m &) && tail -f nohup.out;

Startup script link address: java program self-startup script file

This article is over!

Guess you like

Origin blog.csdn.net/weixin_44299027/article/details/131183967