Debian writes service scripts and sets them to start automatically at boot

Specifically solve the problem: orange pie, debian11 system; set k8s to permanently disable swapoff; and permanently set systemd

1. Create a script file 

vim /opt/software/k8sinitenv.sh

#!/bin/bash
sudo swapoff -a
sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
exit 0     

chmod +777  /opt/software/k8sinitenv.sh


Note that the beginning and end of the sh file are in a fixed format 

2. Set the file as a service, and set the service to start automatically


sudo vim /etc/systemd/system/k8sinitenv.service


[Unit]
Description=k8sinitenv
After=default.target
[Service]
ExecStart=/opt/software/k8sinitenv.sh
[Install]
WantedBy=default.target

sudo systemctl enable /etc/systemd/system/k8sinitenv.service

Note: spaces in the above file 

Service name: k8sinitenv

sudo systemctl enable /etc/systemd/system/k8sinitenv.service Set boot self-start

systemctl status k8sinitenv to view the startup status

systemctl restart k8sinitenv service restart

Guess you like

Origin blog.csdn.net/jiao_zg/article/details/130119672