Как написать сценарий инициализации, который будет выполнять существующий сценарий запуска в Ubuntu 20.04?

мой вопрос похож на: Как написать сценарий инициализации, который выполнит существующий start script?

Однако этот вопрос устарел, и я хотел бы знать, как я могу это сделать в Ubuntu 20.04

Это моя попытка в каталоге init.d: ​​

#! /bin/sh
### BEGIN INIT INFO
# Provides:          myrec
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: your description here
### END INIT INFO

PATH=/home/ahmad/recordings
DESC="Recording audio output"
NAME=myrec
DAEMON=/home/ahmad/recordings/myrec.sh
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
  • Я хотел бы запустить его после выполнения всех процессов , поэтому следует ли мне использовать службу systemd или все в порядке?

  • Должен ли я добавить другой код выше, или он запускает мой файл sh ( myrec.sh )?

В целом Что такое привет мир для выполнения простого bash (чтобы я мог видеть результат) для ubuntu 20.04? Все, что я нашел в сети, устарело

0
задан 24 July 2020 в 10:51

1 ответ

There are two common ways to start a service on Ubuntu:

  1. Making a service file in /etc/init.d directory.

You can check the existing ones as examples. There used to be a template file named skeleton which is no more exists. However you can find a basic example and more help by running man init-d-script.

After creating the file run sudo update-rc.d myservice defaults to install your service (here referred as myservice). refer to update-rec.d, Then you can start and stop your service using sudo service myservice start

  1. The second and recommended or new one is creating a SystemD service.

To know the difference with the above check: Difference between systemctl init.d and service

Here is a simple example of how to create and run your service:

https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/

You can also refer to his manual page for detailed descriptions of these two styles:

http://0pointer.de/public/systemd-man/daemon.html

0
ответ дан 30 July 2020 в 22:04

Другие вопросы по тегам:

Похожие вопросы: