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

bash 复制代码
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

增加可执行权限

bash 复制代码
root@QHTProxy:/opt/openfire/bin# chmod a+x /etc/systemd/system/openfired.service

重新加载systemd服务配置

bash 复制代码
root@QHTProxy:/opt/openfire/bin# systemctl daemon-reload

开启服务:

bash 复制代码
root@QHTProxy:/opt/openfire/bin# systemctl start  openfired 

root@QHTProxy:/opt/openfire/bin# systemctl status  openfired 
● openfired.service - OpenFire
   Loaded: loaded (/etc/systemd/system/openfired.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2023-11-03 11:00:20 CST; 8s ago
 Main PID: 2702 (java)
    Tasks: 59
   Memory: 289.8M
      CPU: 13.435s
   CGroup: /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.S

Nov 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
相关推荐
云泽80818 分钟前
不止是命令:Linux 高频指令实战 + 芯片架构底层逻辑
linux·运维·服务器
j_xxx404_21 分钟前
Linux:基础IO
linux·运维·服务器
angushine2 小时前
银河麒麟V10创建用户
运维
Trouvaille ~2 小时前
【Linux】网络编程基础(二):数据封装与网络传输流程
linux·运维·服务器·网络·c++·tcp/ip·通信
久绊A3 小时前
春节前云平台运维深度巡检-实操经验
运维·安全·容器·kubernetes·云平台
万邦科技Lafite3 小时前
一键获取京东商品评论信息,item_reviewAPI接口指南
java·服务器·数据库·开放api·淘宝开放平台·京东开放平台
梦想的旅途23 小时前
企业微信API外部群自动化推送:从“群发工具”到“智能触达”的架构实践
运维·自动化·企业微信
yuezhilangniao4 小时前
Next.js 项目运维手册-含-常用命令-常见场景
运维·开发语言·reactjs
Trouvaille ~4 小时前
【Linux】网络编程基础(三):Socket编程预备知识
linux·运维·服务器·网络·c++·socket·网络字节序
德迅云安全—珍珍4 小时前
低配服务器性能不够用怎么去优化?
运维·服务器