如何在 Ubuntu 系统上自动启动 Jetbrains 许可证服务器?

如何在 Ubuntu 系统上自动启动 Jetbrains 许可证服务器?

假设我的许可证服务器安装在这里:/opt/jetbrains-license-server,我该如何配置它以自动启动?

答案1

@chris-betti 的回答是正确的。但是对于基于 DEBIAN 的系统,我有三个补充:

  1. 确保运行级别 2 的许可证服务器也已启动
  2. 确保有 jetbrains 用户
  3. 确保 PID 文件位于正确的位置 (/opt//logs/license-server.pid)

广告 1:请参阅下面的脚本文件。您需要将该行更改# Default Start为:

# Default-Start:     2 3 4 5

广告 2:确保您有一个可以启动服务的“jetbrains”系统用户(并且有权在安装许可证服务器的目录中写入

# as root
adduser --system --no-create-home jetbrains
chown jetbrains:nogroup -R /opt/jetbrains-license-server

广告 3:关于 PID 文件,您需要将以下行更改为# pidfile:

# pidfile: /opt/jetbrains-license-server/logs/license-server.pid

安装守护进程

还有一个附加功能可以将服务安装到基于 Debian 的系统(Debian、Ubuntu)的各个运行级别中。这将确保服务在启动时启动并在停止时停止。

# as root
update-rc.d jetbrains-license-server defaults
update-rc.d jetbrains-license-server enable

经过所有修改的剧本

以下是包含所有更改的脚本。

#
# chkconfig: 345 86 14
# description: Jetbrains License Server
# processname: license-server.sh
# pidfile: /opt/jetbrains-license-server/logs/license-server.pid

### BEGIN INIT INFO
# Provides:          jetbrains-license-server
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Jetbrains License Server
# Description:       Manages the Jetbrains License Server Service
### END INIT INFO

APP=jetbrains-license-server
USER=jetbrains
BASE=/opt/jetbrains-license-server

case "$1" in
  # Start command
  start)
    echo "Starting $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh start &> /dev/null"
    ;;
  # Stop command
  stop)
    echo "Stopping $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh stop &> /dev/null"
    echo "$APP stopped successfully"
    ;;
  # Restart command
  restart)
    echo "Restarting $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh restart"
    ;;
  # Status command
  status)
    echo "$APP Status"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh status"
    ;;
  *)
    echo "Usage: /etc/init.d/$APP {start|restart|stop}"
    exit 1
    ;;
esac

exit 0

答案2

jochem 的回答更加透彻和正确,请参考。

首先,在您的服务器上创建一个 jetbrains 用户。

其次,假设您选择使用 init.d(System V),请执行以下操作:

$ touch /etc/init.d/jetbrains-license-server
$ chmod +x /etc/init.d/jetbrains-license-server

现在将以下内容放入此文件中:

#!/bin/bash

# Startup script for Jetbrains License Server
#
# chkconfig: 345 86 14
# description: Jetbrains License Server
# processname: license-server.sh
# pidfile: /opt/jetbrains-license-server/server.pid

### BEGIN INIT INFO
# Provides:          jetbrains-license-server
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Jetbrains License Server
# Description:       Manages the Jetbrains License Server Service
### END INIT INFO

APP=jetbrains-license-server
USER=jetbrains
BASE=/opt/jetbrains-license-server

case "$1" in
  # Start command
  start)
    echo "Starting $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh start &> /dev/null"
    ;;
  # Stop command
  stop)
    echo "Stopping $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh stop &> /dev/null"
    echo "$APP stopped successfully"
    ;;
  # Restart command
  restart)
    echo "Restarting $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh restart"
    ;;
  # Status command
  status)
    echo "$APP Status"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh status"
    ;;
  *)
    echo "Usage: /etc/init.d/$APP {start|restart|stop}"
    exit 1
    ;;
esac

exit 0

答案3

这两个答案都是正确的,尽管它们在一个方面失败了,

如果您正在使用“基础设施即代码”框架(例如 Ansible/Puppet)的脚本,该框架使用状态返回代码来确定要采取什么操作,则所提供的脚本(始终返回 0)将无法在应用程序停止时自动成功启动该应用程序。

我对脚本的补充是捕获每个委托调用的返回代码并将其用作退出代码和底部:

#
# chkconfig: 345 86 14
# description: Jetbrains License Server
# processname: license-server.sh
# pidfile: /opt/jetbrains-license-server/logs/license-server.pid

### BEGIN INIT INFO
# Provides:          jetbrains-license-server
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Jetbrains License Server
# Description:       Manages the Jetbrains License Server Service
### END INIT INFO

APP=jetbrains-license-server
USER=jetbrains
BASE=/opt/jetbrains-license-server
RETCODE=0

case "$1" in
  # Start command
  start)
    echo "Starting $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh start &> /dev/null"
    RETCODE=$?
    ;;
  # Stop command
  stop)
    echo "Stopping $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh stop &> /dev/null"
    RETCODE=$?
    ;;
  # Restart command
  restart)
    echo "Restarting $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh restart"
    RETCODE=$?
    ;;
  # Status command
  status)
    echo "$APP Status"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh status"
    RETCODE=$?
    ;;
  *)
    echo "Usage: /etc/init.d/$APP {start|restart|stop}"
    exit 1
    ;;
esac

exit $RETCODE

您可以扩展此功能以根据返回代码向用户提供有用的消息,但我并没有费心去做那么远。

相关内容