-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinux-Create-Backgroud-Service
37 lines (25 loc) · 1.3 KB
/
Linux-Create-Backgroud-Service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
######################### How to create a background service on ubuntu #########################
It is (in general) no longer necessary to create bash files to manage the service,
systemd takes care of everything (launch, stop, restart, status, log management, etc.)
These configuration files are located in /etc/systemd/system/ and make it possible to indicate
the conditions for activating or deactivating a service, their owner, etc.
Since this folder is essential for the proper functioning of your system, it is advisable to make a backup of it before any file modification.
In a terminal enter :
sudo cp -r /etc/systemd/system /etc/systemd/system.save$(date +%Y%m%d)
Now create a service in system folder :
sudo nano /etc/systemd/system/serviceName.service
The content will be :
[Unit]
Description=Some description of the service
After=mysql.target (Which service will be start before this)
[Service]
ExecStart=Command to be execute on service start
Restart=always
[Install]
WantedBy=multi-user.target
Now we can start the service :
sudo service serviceName start
sudo service serviceName status
sudo service serviceName restart
sudo service serviceName stop
For more info, check this website : https://doc.ubuntu-fr.org/creer_un_service_avec_systemd