写一个linux自定义服务(systemctl),启动一个进程
时间: 2024-02-05 11:04:35 浏览: 80
Sure, here's an example of how to create a custom Linux service using systemd:
1. Create a new file in the `/etc/systemd/system/` directory. For example, let's call it `my-service.service`.
2. Edit the file and add the following lines:
```
[Unit]
Description=My Custom Service
After=network.target
[Service]
ExecStart=/usr/bin/my-process
User=my-user
Group=my-group
[Install]
WantedBy=multi-user.target
```
Here's what each section does:
- `[Unit]` describes the service and its dependencies.
- `[Service]` specifies the command to run and the user/group to run it as.
- `[Install]` sets the target to which the service should be linked.
3. Save the file and reload the systemd configuration:
```
sudo systemctl daemon-reload
```
4. Start the service:
```
sudo systemctl start my-service
```
You can also stop, restart, and check the status of the service using the `systemctl` command. For example:
```
sudo systemctl stop my-service
sudo systemctl restart my-service
sudo systemctl status my-service
```
阅读全文
相关推荐


















