当前位置:网站首页>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
边栏推荐
- Why does the subscript of the array start from 0 instead of 1?
- [untitled] database - limit the number of returned rows
- SQL -- data filtering and grouping
- Database - sorting data
- -- SQL query and return limit rows
- Busybox initrd and initialization process
- 1. Calculate a + B
- Basic knowledge of network in cloud computing
- @Problems caused by internal dead loop of postconstruct method
- What is the difference between the basic feasible solution and the basic feasible solution in linear programming?
猜你喜欢
Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
Automatic control (Han min version)
In depth source code analysis servlet first program
[leetcode 67] sum of two binary numbers
線性代數第二章-矩陣及其運算
On traversal of binary tree
IO multiplexing of 09 redis
Substring Inversion (Easy Version)
Complete example demonstration of creating table to page - joint table query
Generate excel template (drop-down selection, multi-level linkage)
随机推荐
Protected (members modified by protected are visible to this package and its subclasses)
MySQL basic madness theory
String notes
Usage scenario of copyonwritearraylist
St table template
Algèbre linéaire chapitre 2 - matrice et son fonctionnement
線性代數第一章-行列式
Customized communication between threads (reentrantlock)
JSP syntax and JSTL tag
The bottom implementation principle of thread - static agent mode
GNU EFI header file
Fundamentals of SQL: first knowledge of database and SQL - installation and basic introduction - Alibaba cloud Tianchi
2. Devops sonar installation
On traversal of binary tree
Miscellaneous 1
[transfer] MySQL: how many rows of data can InnoDB store in a B + tree?
[leetcode 954] double pair array
Pytorch notes - get familiar with the network construction method by building RESNET (complete code)
lambda expressions
Qthread simple test understanding