Glam Prestige Journal

Bright entertainment trends with youth appeal.

my question similar to: How to write an init script that will execute an existing start script?

However, that question is outdated and I like to know how I can do that in Ubuntu 20.04

This my try in init.d directory:

#! /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
  • I would like to run it after all processes executed, so should I use a systemd service or the above is okay?

  • Should I add other code to above or it runs my sh (myrec.sh) file?

In general What is a hello world for executing a simple bash (so that I can see the result) for ubuntu 20.04? Every thing I found in the web is outdated

0

1 Answer

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:

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy