preface
During the epidemic, let’s first cheer for Wuhan and China!!
Working at home, being 007 every day, feeling that I have been upgraded to panda agent, heart tired, body tired!!
I finally had time to take a break today and document a simple use of Arthas while working from home.
Download and install
Downloading and installing won’t go into that. Post the official website tutorial directly.
Download: curl -o alibaba. Making. IO/arthas/arth…
Start: java-jar arthas-boot.jar
It is important to note that you must use the same user as the target process; otherwise, the process will fail to start.
The problem background
I just put in an assignment the day before yesterday. Due to the wrong hand of a product, the online data was misoperated, so we need help to delete the data.
This is a fucking hole. It’s clearly a hole.
Good foresight, no time to do the task of more or less will write a few back door tools (not to delete the library run, but these back doors in specific circumstances can be used in emergency, as for yourself). But this time the backdoor tool has to be transformed, the middle of the night and can not find people to help you online, they have no authority. Arthas is hot loaded.
The key to the
- Jad decompiles the code
jad --source-only com.xxx.xxx.service.aggregate.AggregateNoRoomService > /tmp/AggregateNoRoomService.java
Copy the code
There is a confidentiality agreement, the package path has been coded, friends can directly watch the process.
- Vim modifies the decompilated code
public AggregateNoRoom getAggregateNoRoom(String agentHotelId) {
List<AggregateNoRoom> aggregateNoRooms = aggregateNoRoomDao.selectList(agentId);
if (CollectionUtils.isEmpty(aggregateNoRooms)) {
return null;
}
// Add new logic
for (AggregateNoRoom room : aggregateNoRooms) {
aggregateNoRoomDao.delete(room.getId())
}
return aggregateNoRooms.get(0);
}
Copy the code
- Recompile this class into a class file
For example, the simple application javac x x x x. Java is ok, but I also rely on other types in the class, so I compiled the entire Java project using Maven directly, and then copied the new class file and uploaded it to the server.
This modified file would normally be recompiled using Arthas’s MC command. But I did not compile successfully on the server, and the cause of the error will be studied later.
- Sc finds the ClassLoader that loads the AggregateNoRoomService
sc -d * AggregateNoRoomService | grep classLoaderHash
The result is classLoaderHash 1b36FA2
- Re-define hot update code
redefine -c 1b36fa2 /tmp/AggregateNoRoomService.class
Re-define success, size :1
It is time to decompile the class using jad to see if the update is actually successful.
Implementing rear door tools
When the magic happens, the data is cleaned up, no ops is asked to give you permission to redeploy, no TL is called to temporarily approve a script. Is too great.
But I still emphasize here, it is best to use with caution, after all, the formal process does not need to carry the blame. (This is very easy to do, and the product brother or product sister will directly ask you to help me repair some data next time, directly bypassing your leader or superior. I really have no black products here, come to hurt each other)
conclusion
Arthas is actually quite powerful and can help us troubleshoot online problems. It is recommended to use Arthas when the environment allows, which will bring a lot of convenience.
Other uses of Arthas will be updated in the future. If you like, please follow me on my official account.
-
Writing is not easy, reprint please indicate the source, like small partners can pay attention to the public number to view more like the article.
-
Contact: [email protected]
-
QQ:95472323
-
WeChat: ffj2000