Writing shell scripts to start and stop programs

Source: Internet
Author: User
Tags stop script

The two-day project online

I've been busy.

Three days overtime.

But there's still a harvest.

Premise:

When you write the startup script start.sh, cycle to start the change process

While True

Java-jar Xxx.jar

Done

When starting, of course, start the command in the background

Nohup start.sh &

At this point, if you want to turn off the change script, what do you do now?

Had to Ps-ef|grep start.sh

and kill this thread.

This is very troublesome and unsafe, in case you kill someone else's thread, that ...

Then write a stop script.

When thinking:

When you start the script, touch a file Start.flag

Before each cycle after starting to determine whether there are stop.flag

If it does, the stop script has started

Stops the loop and deletes the Start.flag

In the Stop script, first determine if there is a Start.flag

If there is a start.flag, create the Stop.flag

If there is no Start.flag, the startup script is not running

If you determine that Start.flag has been deleted, the startup program has stopped and deleted Stop.flag

Done

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.