Linux article---use systemctl start xxx to start your own program|boot startup|daemon process

Linux article---use systemctl start xxx to start your own program|boot startup|daemon process

  • Machine: Nvidia Jetson Xavier
  • System: ubuntu 18.04

Recently, I am using symfony's console component and need to execute a background php process and keep the background process existing. Here I am using the Systemctl command. Systemctl is a collection of system management daemons, tools and libraries. I will post my configuration directly later, for reference only:

1. Create a service

cd /etc/systemd/system
sudo vim app.service

The content of app.service is as follows:
Run python script

[Unit]
Description=app
After=network.target

[Service]
User=nvidia
ExecStart=/usr/bin/python3 /home/nvidia/app/yolov4_pre/app_test_time.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
  • If you want to change sudo, just change User to root. There is no need to add sudo in front of ExecStart. The details are as follows
[Unit]
Description=app
After=network.target

[Service]
User=nvidia
ExecStart=/usr/bin/python3 /home/nvidia/app/yolov4_pre/app_test_time.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

2. Modify permissions

sudo chmod +x app.service

3. Start the service

sudo systemctl daemon-reload
sudo systemctl start app.service
sudo systemctl status app.service

Insert image description here

4. Test

Will the kill python program start automatically?
Insert image description hereYou can see from the picture below that it has been updated. .
Insert image description here

Guess you like

Origin blog.csdn.net/m0_46825740/article/details/132500448