当前位置: 首页 > news >正文

Ubuntu 增加服务 比如openfire

在Ubuntu上,可以使用systemd来管理和配置服务。下面是将命令添加为服务的一般步骤:

创建一个.service文件,该文件描述了您要添加的服务。打开终端,并使用以下命令创建一个新的服务文件:

sudo nano /etc/systemd/system/my-service.service
在打开的文件中,输入以下内容(请根据您的需求进行适当修改):

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

[Service]
ExecStart=/path/to/your/command
WorkingDirectory=/path/to/working/directory
Restart=always

[Install]
WantedBy=multi-user.target
Description:服务的简短描述。
After:指定服务应在哪个目标之后启动(例如network.target表示在网络连接之后启动)。
ExecStart:要执行的命令或脚本的路径。
WorkingDirectory:命令执行的工作目录。
Restart:定义服务在发生错误或停止后是否应自动重启。
WantedBy:指定服务所属的目标。
保存并关闭文件。使用Ctrl + X,然后按Y确认保存,最后按Enter键退出编辑器。

让系统重新加载systemd服务配置:

sudo systemctl daemon-reload
启动服务并设置其在系统启动时自动启动:

sudo systemctl start my-service
sudo systemctl enable my-service
start:启动服务。
enable:设置服务在系统启动时自动启动。
现在,您的命令已经以服务的形式添加到Ubuntu中,并且可以通过systemctl命令启动、停止和管理该服务。例如:

sudo systemctl start my-service    # 启动服务
sudo systemctl stop my-service     # 停止服务
sudo systemctl restart my-service  # 重启服务
sudo systemctl status my-service   # 查看服务状态

--------------------------------------------------------------------

针对openfire,下载的tar.gz解压缩文件目录如下:

root@QHTProxy:/opt/openfire/bin# ls
extra  openfire  openfire.sh  openfirectl

在/etc/systemd/system下面新建文件 openfired.service 

root@QHTProxy:/opt/openfire/bin#  cat /etc/systemd/system/openfired.service 
[Unit]
Description=OpenFire
After=network.target[Service]
ExecStart=/opt/openfire/bin/openfire.sh
WorkingDirectory=/opt/openfire/bin
Restart=always[Install]
WantedBy=multi-user.target

增加可执行权限 

root@QHTProxy:/opt/openfire/bin# chmod a+x /etc/systemd/system/openfired.service

重新加载systemd服务配置

root@QHTProxy:/opt/openfire/bin# systemctl daemon-reload

开启服务:

root@QHTProxy:/opt/openfire/bin# systemctl start  openfired root@QHTProxy:/opt/openfire/bin# systemctl status  openfired 
● openfired.service - OpenFireLoaded: loaded (/etc/systemd/system/openfired.service; enabled; vendor preset: enabled)Active: active (running) since Fri 2023-11-03 11:00:20 CST; 8s agoMain PID: 2702 (java)Tasks: 59Memory: 289.8MCPU: 13.435sCGroup: /system.slice/openfired.service└─2702 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Dlog4j.configurationFile=/opt/openfire/lib/log4j2.xml -Dlog4j2.formatMsgNoLookups=true -Djdk.tls.ephemeralDHKeySize=matched -Djsse.SNov 03 11:00:20 QHTProxy systemd[1]: Started OpenFire.
Nov 03 11:00:20 QHTProxy openfire.sh[2702]: /opt/openfire/bin/openfire.sh: 21: /opt/openfire/bin/openfire.sh: shopt: not found
Nov 03 11:00:23 QHTProxy openfire.sh[2702]: Openfire 4.7.5 [2023-11-3 11:00:23]
Nov 03 11:00:24 QHTProxy openfire.sh[2702]: 管理平台开始监听:
Nov 03 11:00:24 QHTProxy openfire.sh[2702]:   http://qhtproxy:9090
Nov 03 11:00:24 QHTProxy openfire.sh[2702]:   https://qhtproxy:9091
Nov 03 11:00:24 QHTProxy openfire.sh[2702]: Successfully loaded plugin 'admin'.
Nov 03 11:00:24 QHTProxy openfire.sh[2702]: Successfully loaded plugin 'search-1.7.3'.
Nov 03 11:00:24 QHTProxy openfire.sh[2702]: Successfully loaded plugin 'userimport

http://www.lryc.cn/news/219312.html

相关文章:

  • 海康Visionmaster-全局变量:全局变量关联流程中具体 模块结果的方法
  • Eureka介绍和使用
  • Incremental Object Detection via Meta-Learning【论文解析】
  • AI大模型时代网络安全攻防对抗升级,瑞数信息变革“下一代应用与数据安全”
  • 后端接口接收对象和文件集合,formdata传递数组对象
  • python json包
  • 基于 NGram 分词,优化 Es 搜索逻辑,并深入理解了 matchPhraseQuery 与 termQuery
  • PivotNet:Vectorized Pivot Learning for End-to-end HD Map Construction
  • 阿里云安全恶意程序检测
  • Xcode中如何操作Git
  • 浅述边缘计算场景下的云边端协同融合架构的应用场景示例
  • C++中禁止在栈中实例化的类
  • MsgPack和Protobuf
  • 自定义类型联合体
  • 【Shell 系列教程】Shell printf 命令( 六)
  • 2022年电工杯数学建模B题5G网络环境下应急物资配送问题求解全过程论文及程序
  • git reflog 恢复git reset --hard 回退的内容
  • kali Linux中更换为阿里镜像源
  • 【每日一题】移除链表元素(C语言)
  • stm32 ADC
  • linux网络服务综合项目
  • 每日一题(LeetCode)----数组--移除元素(三)
  • AI:57-基于机器学习的番茄叶部病害图像识别
  • 人工智能-深度学习计算:层和块
  • Linux第一个小程序进度条
  • JavaEE平台技术——预备知识(Maven、Docker)
  • 【ChatOCR】OCR+LLM定制化关键信息抽取(附开源大语言模型汇总整理)
  • 【位运算】XOR Construction—CF1895D
  • 解决Visual Studio Code 控制台中文乱码问题
  • React Native自学笔记