使用Mac&上的脚本重新启动Play Framework Activator. linux [英] Restart Play Framework Activator using a script on mac & linux

查看:144
本文介绍了使用Mac&上的脚本重新启动Play Framework Activator. linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个脚本,该脚本可以重新启动在指定端口上运行的激活器实例.我通常在端口15000上运行我的激活器项目,我的目标是使用脚本重新启动它.然后,我可以稍后从网页中调用该脚本,以使激活器远程重启等.

I am trying to develop a script that can restart an activator instance running on a specified port. I normally run my activator project at port 15000 and I am aiming to have it restarted using the script. I can then later call that script from a web page to have activator restarted remotely etc.

到目前为止,我在Linux中找到了一个非常方便的实用程序,名为fuser,它可以找到在指定端口侦听的进程并将其杀死.像这样:

So far I found a really handy utility in Linux called fuser which can find a process listening at a specified port and kill it. Something like:

fuser -k 15000/tcp可以在Linux上正常运行,但不能在Mac上运行.

fuser -k 15000/tcp which works fine on linux but NOT on a mac.

我想我还需要以某种方式跟踪激活器项目的位置,以便以后启动它.

I guess I would also need to somehow track the activator project location to start it later.

请告诉我您有关如何完成此操作的建议和意见.

Please let me know your suggestions and comments on how this can be done.

推荐答案

我正在为此使用bash文件.它可以在Linux和Mac OS上运行.

I'm using a bash file for this. It works on Linux and Mac OS.

它名为loader.sh,并放入您的发行版根目录.

It's named loader.sh and put into your distributions root.

要停止运行,请使用kill命令和存储在RUNNING_PID中的PID.

To stop it uses the kill command and the PID stored in RUNNING_PID.

#!/bin/bash

# Change IP address and port here
address="127.0.0.1"
port="9000"

# Get directory and add it to PATH
dir="$( cd "$( dirname "$0" )" && pwd )"
export PATH="$dir:$dir/bin:$PATH"

function start() {
    # Check if we started already
    [ -f $dir/RUNNING_PID ] && return

    echo -n "Starting"

    # You can specify a config file with -Dconfig.resource
    # or a secret with -Dplay.crypto.secret
    myApp -Dhttp.port=$port -Dhttp.address=$address > /dev/null &

    echo "...started"
}

function stop() {
    [ -f $dir/RUNNING_PID ] || return
    echo -n "Stopping"
    kill -SIGTERM $(cat $dir/RUNNING_PID)
    while [ -f $dir/RUNNING_PID ]
    do
        sleep 0.5
    done

    echo "...stopped"
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: loader.sh start|stop|restart"
        exit 1
        ;;
esac

这篇关于使用Mac&上的脚本重新启动Play Framework Activator. linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆