当前位置:网站首页>How SYSTEMd uses / etc / init D script
How SYSTEMd uses / etc / init D script
2022-04-23 06:28:00 【lingedeng】
1. With apport For example , take /etc/init.d/apport Copy and generate new myapport, The contents are as follows :
#! /bin/sh
### BEGIN INIT INFO
# Provides: myapport
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: myapport init.d with systemd test"
### END INIT INFO
DESC="myapport init.d with systemd test"
NAME=myapport
SCRIPTNAME=/etc/init.d/$NAME
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
echo "myapport started"
return 0
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
echo "myapport stopped"
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC:" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC:" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart|force-reload)
$0 stop || true
$0 start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
2. stay /etc/rc?.d In any one (? Value 2 3 4 5), Establish symbolic links , Point to /etc/init.d/myapport
lrwxrwxrwx 1 root root 18 9 month 29 16:43 S01myapport -> ../init.d/myapport
notes : If you don't establish relevant symbolic links , It means that SysV The service is not enabled , Then... Will not be executed when the system starts .
3. Restart the machine and check myapport Service related information
$ systemctl status myapport
● myapport.service - LSB: myapport init.d with systemd test"
Loaded: loaded (/etc/init.d/myapport; generated)
Active: inactive (dead) since Wed 2021-09-29 16:56:23 CST; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 2771 ExecStop=/etc/init.d/myapport stop (code=exited, status=0/SUCCESS)
Process: 979 ExecStart=/etc/init.d/myapport start (code=exited, status=0/SUCCESS)
9 month 29 16:54:25 eric-vm-dev systemd[1]: Starting LSB: myapport init.d with systemd test"...
9 month 29 16:54:29 eric-vm-dev myapport[979]: * Starting myapport init.d with systemd test: myapport
9 month 29 16:54:29 eric-vm-dev myapport[979]: myapport started
9 month 29 16:54:29 eric-vm-dev myapport[979]: ...done.
9 month 29 16:54:29 eric-vm-dev systemd[1]: Started LSB: myapport init.d with systemd test".
$ systemctl list-unit-files | grep myapport
myapport.service generated
notes :generated Indicates that the service unit is composed of systemd-sysv-generator Application generation .
$ systemctl cat myapport
# /run/systemd/generator.late/myapport.service
# Automatically generated by systemd-sysv-generator
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/myapport
Description=LSB: myapport init.d with systemd test"
Before=graphical.target
After=remote-fs.target
[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/myapport start
ExecStop=/etc/init.d/myapport stop
Reference resources :
版权声明
本文为[lingedeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210616198580.html
边栏推荐
- Basic knowledge of network in cloud computing
- 10.Advance Next Round
- [leetcode 6] zigzag transformation
- Preparedstatement prevents SQL injection
- Explain of MySQL optimization
- What is the difference between the basic feasible solution and the basic feasible solution in linear programming?
- 3. Continuous integer
- [leetcode217] there are duplicate elements
- Introduction to virtualization features
- [leetcode 290] word rules
猜你喜欢
Automatic control (Han min version)
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
Linear algebra Chapter 1 - determinant
IO multiplexing of 09 redis
Kibana search syntax
Installation and usage skills of idea
SQL -- data filtering and grouping
Explanation of login page
随机推荐
2. Devops sonar installation
Miscellaneous 1
Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
Addition, deletion, modification and query of MySQL table
Integration and induction of knowledge points of automatic control principle (Han min version)
LockSupport. Park and unpark, wait and notify
MySQL table constraints and table design
Generate excel template (drop-down selection, multi-level linkage)
Collection and map thread safety problem solving
MySQL basic madness theory
Programming training
Storing inherited knowledge in cloud computing
Numpy common function table sorting of data processing
Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
[leetcode 54] spiral matrix
Techniques et principes de détection
Consistent hash algorithm used for redis cache load balancing
container
JDBC tool class encapsulation