当前位置: 首页> 财经> 创投人物 > 制作公司网页软件_游戏推广赚佣金平台_智能建站系统_seo网上课程

制作公司网页软件_游戏推广赚佣金平台_智能建站系统_seo网上课程

时间:2025/7/19 22:19:34来源:https://blog.csdn.net/simpleman2000/article/details/144141026 浏览次数:0次
制作公司网页软件_游戏推广赚佣金平台_智能建站系统_seo网上课程

目录

  • 创建服务
  • 创建另一个服务,用于执行更新操作
  • 给你的用户配置一些systemctl命令权限

创建服务

/etc/systemd/system下新建服务配置文件:yourapp.service,内容如下:

[Unit]
Description=yourapp
After=network.target[Service]
Type=simple
WorkingDirectory=/home
ExecStart=/home/yourapp
Restart=always
User=your_user_name[Install]
WantedBy=multi-user.target

如果你是修改现有的配置文件,需要让systemctl重载一下:

systemctl stop yourapp
systemctl disable yourapp.service
systemctl daemon-reload

启动服务:

systemctl enable yourapp
systemctl start yourapp

创建另一个服务,用于执行更新操作

程序要更新,不能自己下载更新文件,然后覆盖自己,有可能会报异常:文件无法改写。
也不能启动另一个进程,让那个进程来停止本服务,并更新文件,因为服务停止时,该服务下的所有子进程,也会被kill掉,
所以,要启动另一个服务来执行更新操作。

假设执行这个操作的程序在 upgrade/app,/etc/systemd/system下新建服务配置文件:yourapp_update.service,内容如下:

[Unit]
Description=yourapp_update
After=network.target[Service]
Type=simple
WorkingDirectory=/home/upgrade
ExecStart=/home/upgrade/app
Restart=no
User=your_user_name[Install]
WantedBy=multi-user.target

注意:Restart=no,这个程序无须自动重启

激活服务,无须启动该服务:

systemctl enable yourapp_update

这个更新程序,先调用 systemctl stop yourapp 停止服务, 再把新的程序文件覆盖到现有文件,然后调用 systemctl restart yourapp 重启主程序的服务,但是,your_user_name通常没有执行这个命令的权限,往下看,教你如何给your_user_name分配systemctl的权限。

给你的用户配置一些systemctl命令权限

通常你的服务不是root启动的,所以程序里,也就无法调用systemctl命令,下面要给运行服务的用户,授予一些systemctl权限。

在/etc/sudoers.d路径下,创建文件 yourapp,确认此文件所有人为 root,文件权限是 440(chmod 440 文件名)。
文件内容:

your_user_name ALL=(ALL) NOPASSWD: /bin/systemctl restart yourapp.service
your_user_name ALL=(ALL) NOPASSWD: /bin/systemctl start yourapp.service
your_user_name ALL=(ALL) NOPASSWD: /bin/systemctl stop yourapp.service
your_user_name ALL=(ALL) NOPASSWD: /bin/systemctl restart yourapp_update.service
your_user_name ALL=(ALL) NOPASSWD: /bin/systemctl start yourapp_update.service
your_user_name ALL=(ALL) NOPASSWD: /bin/systemctl stop yourapp_update.service

这样,your_user_name 用户就有控制这两个服务的权限了。

关键字:制作公司网页软件_游戏推广赚佣金平台_智能建站系统_seo网上课程

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: