Linux service management two ways service and systemctl

Linux service management two ways service and systemctl

(1) Service

The service command is actually going to the /etc/init.d directory to perform related procedures

# service command launched the Redis script

Service Redis Start

#Lut directly Redis script

/etc/init.d/redis start

#Toot self-starting? Script requires us to write

# pwd

/Tomcat/apache-tomcat-7.0.81/bin

# ./startup.sh

Using catalina_base: /tomcat/apache-tomcat-7.0.81

Using catalina_home: /tomcat/apache-tomcat-7.0.81

Using catalina_tmpdir: /tomcat/apache-tomcat-7.0.81/temp

Using JRE_HOME: /JAVA/JDK1.6.0_45

Using classpath: /tomcat/apache-tomcat-7.0.81/bin/bootstrap.jar: /tomcat/apache-tomcat-7.0.81/bin/tomcat-juli.jar

Tomcat start.

[root @ localhost bin] # jps

4558 bootstrap

4567 JPS

Launch Tomcat with Service Tomcat Start under Linux

1. Create a Tomcat file in /etc/init.d

2. Copy the following code to the Tomcat file. You need to modify it according to your own JDK, Tomcat address

#! / bin / sh

# chkConfig: 345 99 10

# Description: Auto-Starts Tomcat

# /etc/init.d/tomcatd

# Tomcat Auto-Start

# Source Function Library.

#. /etc/init.d/functions

# Source NetWorking Configuration.

#. / etc / sysconfig / network

RetVal = 0

# Set according to your address

Export java_home = / usr / java / jdk1.6.0_45

Export jre_home = / usr / java / jdk1.6.0_45 / jre

Export catalina_home = / usr / Tomcat / apache-tomcat-7.0.81

EXPORT CATALINA_BASE = / usr / tomcat / apache-tomcat-7.0.81

start ()

{

IF [-f $ CATALINA_HOME / BIN / Startup.sh];

THEN

Echo $ “Starting Tomcat”

$ Catalina_home / bin / startup.sh

RetVal = $?

Echo “OK”

Return $ RetVal

Fi

}

STOP ()

{

IF [-f $ catalina_home / bin / shutdown.sh];

THEN

Echo $ “stopping tomcat”

$ Catalina_home / bin / shutdown.sh

RetVal = $?

Sleep 1

PS -FWWU root | GREP Tomcat | grep -v grep | grep -v pid | awk ‘{print $ 2}’ | xargs kill -9

Echo “OK”

# [$ RETVAL-EQ 0] && RM -F / VAR / LOCK / …

Return $ RetVal

Fi

}

Case “$ 1” in

START)

Start

;

STOP)

STOP

;

RESTART)

Echo $ “Restarying Tomcat”

$ 0 stopsleep 1

$ 0 Start

;

*)

Echo $ “Usage: $ 0 {start | stop | restart}”

EXIT 1

;

ESAC

EXIT $ RETVAL

3. Set the permissions:

CHMOD 755 Tomcat

4. Add to System Services

Chkconfig –Add Tomcat

5. View system service:

Chkconfig –List

6. Start, stop Tomcat:

Service tomcat start

Service Tomcat Stop

Service management

Systemctl Start Service Name Open Service

SystemctL STOP Service Name Off Service

Systemctl status service name display status

Systemctl Restart Service Name Restart Service

Systemctl enable service name boot start service

Systemctl Disable service name is forbidden to boot start

Systemctl List-Units View all running services in the system

Systemctl List-Unit-files View the boot start state of all services in the system

Systemctl List-Dependencies Service Name View the dependencies of services in the system

SYSTEMCTL MASK service name freezing service

Systemctl Unmask Service Name Jelly Service

Systemctl set-default multi-user.target does not start the graphical interface when booting

Systemctl set-default graphical.target starts graphics interface when booting

Last looks to me who landed me

w Use Who is using me?

Lastb View Who tried to log in to me but failed

/etc/init.d/ ===> The service startup script placement.

/ etc / sysconfig / ===> The initialization environment profile of each service.

/etc/xinetd.conf/ and /etc/xinetd.d ===> super daemon configuration file

/ etc / ===> each of the respective configuration files

/ var / lib / ===> Database generated by each service

/ var / run / ===> Process PID records for each service

(2) Systemctl management Tomcat starts, stop, restart, boot start

Create a service

Create a script file Tomcat.Service in the / lib / systemd / system directory

2. Create a soft link

Ln -s /lib/systemd/system/tomcat.service /etc/systemd/system/multi-user.target.wants/tomcat.service

3. Refresh configuration

Systemctl daemon-reloaders

4. Start, restart, stop

Systemctl Start Tomcat

Systemctl Restart Tomcat

Systemctl Stop Tomcat

5. Boot start

Systemctl Enable Tomcat

Prohibit boot start

Systemctl Disable Tomcat

6. View status

Systemctl Status Tomcat

Related Posts