linux 进程开机自启

linux 进程开机自启

在Linux系统中,要让一个进程在开机时自动启动,可以使用systemd服务。

以下是创建自启动服务的步骤和示例代码:

创建一个新的systemd服务单元文件。

文件通常位于/etc/systemd/system/目录下,以.service作为文件扩展名。例如,创建一个名为my_service.service的文件:

sudo nano /etc/systemd/system/my_service.service

在该文件中添加以下内容:

**[Unit]
Description=My Custom Service
After=network.target

Service

Type=simple
ExecStart=/path/to/your/application

Install

WantedBy=multi-user.target**

将/path/to/your/application替换为你的应用程序的完整路径。

重新加载systemd管理器配置。sudo systemctl daemon-reload

启用服务以在开机时自动启动。sudo systemctl enable my_service.service

(可选)立即启动服务而不需要重启。sudo systemctl start my_service.service

确保你的应用程序具有执行权限。如果没有,使用chmod命令添加执行权限:

sudo chmod +x /path/to/your/application

现在,每次系统启动时,my_service.service服务都会自动运行指定的应用程序。

bash 复制代码
:~/Documents/IsstaGao/pwr_mngr$
:~/Documents/IsstaGao/pwr_mngr$ vim /etc/systemd/system/my_service.service
:~/Documents/IsstaGao/pwr_mngr$ sudo vim /etc/systemd/system/issta_service.service
[sudo] password for mogo:
:~/Documents/IsstaGao/pwr_mngr$ sudo vim /etc/systemd/system/issta_service.service
:~/Documents/IsstaGao/pwr_mngr$ pwd
/data/mogo/Documents/IsstaGao/pwr_mngr
:~/Documents/IsstaGao/pwr_mngr$ sudo vim /etc/systemd/system/issta_service.service
:~/Documents/IsstaGao/pwr_mngr$ sudo systemctl daemon-reload
:~/Documents/IsstaGao/pwr_mngr$ sudo systemctl enable issta_service.service
Created symlink /etc/systemd/system/multi-user.target.wants/issta_service.service → /etc/systemd/system/issta_service.service.
:~/Documents/IsstaGao/pwr_mngr$ sudo systemctl start issta_service.service
:~/Documents/IsstaGao/pwr_mngr$ ps -aux | grep client
root        8843  0.0  0.0  10432   540 ?        Ssl  16:15   0:00 /data/mogo/Documents/IsstaGao/pwr_mngr/client -s 192.168.1.102 -p 9039
mogo        8857  0.0  0.0   8572   652 pts/0    S+   16:16   0:00 grep --color=auto client
相关推荐
哎哟喂呢哈11 小时前
ddns 免费 ipv6
linux
Flash.kkl11 小时前
Linux——线程的同步和互斥
linux·开发语言·c++
sunfove11 小时前
Python 面向对象编程:从过程式思维到对象模型
linux·开发语言·python
小宇的天下11 小时前
Calibre 3Dstack --每日一个命令day13【enclosure】(3-13)
服务器·前端·数据库
云和数据.ChenGuang11 小时前
达梦数据库安装服务故障四
linux·服务器·数据库·达梦数据库·达梦数据
weixin_5160230711 小时前
ssh配合密钥连接
服务器·网络·ssh
PPPPPaPeR.11 小时前
使用vim实现进度条(初级)
linux·编辑器·vim
tobias.b12 小时前
408真题解析-2009-36-网络-交换机转发机制
网络·智能路由器·408考研·408真题解析
纵有疾風起12 小时前
【Linux 系统开发】基础开发工具详解:自动化构建、版本控制与调试器开发实战
linux·服务器·开发语言·c++·经验分享·开源·bash
wtsolutions12 小时前
Advanced Features - Unlocking the Power of JSON to Excel Pro
linux·json·excel