
测试好使!
#!/bin/bash
nginxdir=`find / -name nginx|grep nginx/sbin/nginx|awk -F sbin '{print $1}'`
while true
do
clear
# menu
echo "
本机Nginx路径为: $nginxdir"
echo "
****************** Nginx tool *******************
* *"
echo "* (1) 启动Nginx *"
echo "* (2) 关闭Nginx *"
echo "* (3) 重启Nginx *"
echo "* (4) 查看Nginx运行进程数 *"
echo "* (5) 查看TCP连接状态 *"
echo "* (10) 添加虚拟主机 *"
echo "* (0) 退出本程序 *"
echo "* *
*************************************************"
read -p "请输入对应数字: " caozuo
case $caozuo in
# start
1) if [ -z "`ps ax|grep nginx|grep -v grep|grep -v nginx.sh|awk '{print $1}'`" ];
then
$nginxdir/sbin/nginx
sleep 1
if [ -z "`ps ax|grep nginx|grep -v grep|grep -v nginx.sh|awk '{print $1}'`" ];
then
read -p "Nginx 启动失败!"
else
read -p "Nginx 启动完成!回车继续!"
fi
else
read -p "Nginx is Running! 回车继续!"
fi
;;
#stop
2) killall nginx
sleep 1
if [ -z "`ps ax|grep nginx|grep -v grep|grep -v nginx.sh|awk '{print $1}'`" ];
then
read -p "Nginx关闭完成!回车继续!"
else
read -p "Nginx关闭失败!回车继续!"
fi
;;
#restart
3) if [ -z "`ps ax|grep nginx|grep -v grep|grep -v nginx.sh|awk '{print $1}'`" ];
then
$nginxdir/sbin/nginx
read -p "Nginx启动完成!回车继续!"
else
killall nginx
sleep 1
$nginxdir/sbin/nginx
read -p "Nginx重启完成!回车继续!"
fi
;;
#process
4) read -p "Nginx运行进程数: `ps -ef|grep nginx|grep -v nginx.sh|grep -v grep|wc -l`"
;;
#TCP
5) read -p "TCP连接状态:
`netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"t",state[key]}'`"
;;
#vhost
10)
while true
do
clear
read -p "请输入要添加的虚拟主机完整域名: " vhost
read -p "请输入该域名使用的端口: " prot
read -p "请输入域名对应的root目录: " hostdir
read -p "请输入访问日志目录: " logdir
echo "
################### 确认以下信息 ########################
"
read -p "Nginx的目录为: $nginxdir
要添加的虚拟主机为: $vhost
该域名对应的端口为: $prot
域名对应的root目录为: $hostdir
访问日志文件为: $logdir/$vhost.log
#########################################################
[回车继续,如有误请输入0返回]:" queren2
case $queren2 in
0) break
;;
*)
mkdir $nginxdir/conf/vhost
touch $nginxdir/conf/vhost/$vhost.conf
sed -i "/include * mime.types/ a \include $nginxdir\/conf\/vhost\/$vhost.conf;" $nginxdir/conf/nginx.conf
echo 'server
{
listen '$prot';
server_name '$vhost';
index index.php index.html index.htm;
root '$hostdir';
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=/$1 last;
rewrite ^(.*)$ /index.php/$1 last;
}
}
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log '$logdir/$vhost.log';
}' >>$nginxdir/conf/vhost/$vhost.conf
read -p "添加完成,需重启Nginx生效,回车返回!"
break
;;
esac
done
;;
0) break
;;
*) read -p "请输入对应数字!或者Ctrl+C退出!回车继续!"
;;
esac
done我正在使用i18n从头开始构建一个多语言网络应用程序,虽然我自己可以处理一大堆yml文件,但我说的语言(非常)有限,最终我想寻求外部帮助帮助。我想知道这里是否有人在使用UI插件/gem(与django上的django-rosetta不同)来处理多个翻译器,其中一些翻译器不愿意或无法处理存储库中的100多个文件,处理语言数据。谢谢&问候,安德拉斯(如果您已经在rubyonrails-talk上遇到了这个问题,我们深表歉意) 最佳答案 有一个rails3branchofthetolkgem在github上。您可以通过在Gemfi
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我有一个在Linux服务器上运行的ruby脚本。它不使用rails或任何东西。它基本上是一个命令行ruby脚本,可以像这样传递参数:./ruby_script.rbarg1arg2如何将参数抽象到配置文件(例如yaml文件或其他文件)中?您能否举例说明如何做到这一点?提前谢谢你。 最佳答案 首先,您可以运行一个写入YAML配置文件的独立脚本:require"yaml"File.write("path_to_yaml_file",[arg1,arg2].to_yaml)然后,在您的应用中阅读它:require"yaml"arg
这可能是个愚蠢的问题。但是,我是一个新手......你怎么能在交互式rubyshell中有多行代码?好像你只能有一条长线。按回车键运行代码。无论如何我可以在不运行代码的情况下跳到下一行吗?再次抱歉,如果这是一个愚蠢的问题。谢谢。 最佳答案 这是一个例子:2.1.2:053>a=1=>12.1.2:054>b=2=>22.1.2:055>a+b=>32.1.2:056>ifa>b#Thecode‘if..."startsthedefinitionoftheconditionalstatement.2.1.2:057?>puts"f
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge