Ways to create Linux system services _linux Shell

Source: Internet
Author: User
Tags sleep

Linux Environment: Ubuntu

Copy Code code as follows:

#! /bin/sh
# Provides:server.sh
# Default-start:2 3 4 5
# Short-description:server Testing ...

Exec_path=/home/huangmin/cdev/project
Exec=server
Pid_file=/var/run/server.sh.pid
Daemon=/home/huangmin/cdev/project/server

if! [-X $EXEC _path/$EXEC]; Then
echo "ERROR: $EXEC _path/$EXEC not found ..."
Exit 1
Fi

Stop () {
echo "Stopping $EXEC ..."
Killall $DAEMON >/dev/null
Rm-f $PID _file
Sleep 1
echo "Shutting down $EXEC: [OK]"
}

Start () {
echo "Starting $EXEC ..."
$DAEMON >/dev/null
Pidof $EXEC > $PID _file
Sleep 1
echo "Starting $EXEC: [OK]"
}

Restart () {
Stop
Start
}

Case "$" in
Start
Start

Stop
Stop

Restart)
Restart

Status
echo "Status here"

*)
echo "Usage:service $EXEC {start|stop|restart|status}"
Exit 1
Esac

Exit $?

/home/huangmin/cdev/project/server is the program that we need as a system service.
After writing a script, place it in the directory/etc/init.d, or make a soft link form such as: sudo ln-s/home/huangmin/cdev/project/bash/server.sh/etc/init.d/ Servertest.sh
Finally adds it to the system service using the Chkconfig command: Chkconfig–add servertest.sh
can use the command service servertest.sh Start starts the service

immediately.

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.