Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm using the init.d script from this: http://wiki.nginx.org/RedHatNginxInitScript but this script sucks on my CentOS 5.5 nginx 1.0.6 (which installed by passenger).
It sucks for 2 reasons:
When I run service nginx start, it start nginx but then do not quit it self.
It run in some different runtime path ($PATH) so that rails won't be able to find executables located inside /usr/local/bin (like node.js)
Is there any init.d script that works for you guys (on CentOS or other Redhat based distribution) that does not have these problems?
The one here: http://articles.slicehost.com/2009/2/2/centos-adding-an-nginx-init-script has worked for me in the past.
You will need to change the paths to "/etc/nginx" instead of "/usr/local/nginx" for instance.
Actually both are similar except that your old one has an additional "MakeDirs" function. Not sure why this may this be needed.
My current one is below:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
sysconfig="/etc/sysconfig/$prog"
lockfile="/var/lock/subsys/nginx"
pidfile="/var/run/${prog}.pid"
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f $sysconfig ] && . $sysconfig
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest_q || return 6
stop
start
}
reload() {
configtest_q || return 6
echo -n $"Reloading $prog: "
killproc -p $pidfile $prog -HUP
echo
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
configtest_q() {
$nginx -t -q -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
# Upgrade the binary with no downtime.
upgrade() {
local oldbin_pidfile="${pidfile}.oldbin"
configtest_q || return 6
echo -n $"Upgrading $prog: "
killproc -p $pidfile $prog -USR2
retval=$?
sleep 1
if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then
killproc -p $oldbin_pidfile $prog -QUIT
success $"$prog online upgrade"
echo
return 0
else
failure $"$prog online upgrade"
echo
return 1
fi
}
# Tell nginx to reopen logs
reopen_logs() {
configtest_q || return 6
echo -n $"Reopening $prog logs: "
killproc -p $pidfile $prog -USR1
retval=$?
echo
return $retval
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest|reopen_logs)
$1
;;
force-reload|upgrade)
rh_status_q || exit 7
upgrade
;;
reload)
rh_status_q || exit 7
$1
;;
status|status_q)
rh_$1
;;
condrestart|try-restart)
rh_status_q || exit 7
restart
;;
*)
echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
exit 2
esac
This is what is distributed with the Nginx RPM from EPEL.
Related
macOS Catalina, installed jenv 0.5.4 using homebrew, using zsh, followed all the steps listed in https://www.jenv.be/
In terminal I have the following error
Last login: Tue Dec 22 10:10:15 on ttys002
/usr/local/Cellar/jenv/0.5.4/libexec/libexec/jenv-refresh-plugins: line 14: /Users/username/.jenv/jenv.version: Permission denied
The below is the code from jenv-refresh-plugins
#!/usr/bin/env bash
# Summary: Refresh plugins links
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
set -e
[ -n "$JENV_DEBUG" ] && set -x
FORCE_REFRESH=0
if [ ! -f "${JENV_ROOT}/jenv.version" ]; then
echo "NONE" > ${JENV_ROOT}/jenv.version
fi
if [ "$1" = "--complete" ]; then
echo "--force"
exit
fi
if [ "$1" = "--force" ]; then
FORCE_REFRESH=1
fi
lastVersion=$(cat "${JENV_ROOT}/jenv.version" || echo "none")
currentVersion=$(jenv --version)
if [ ! "$lastVersion" == "$currentVersion" ] || [ $FORCE_REFRESH == "1" ]; then
echo "jenv has been updated, process to refresh plugin links"
for path in "${JENV_ROOT}/plugins/"*; do
if [ -L "$path" ]; then
pluginName=$(basename $path)
echo "Refresh plugin $pluginName"
ln -sfn "${JENV_INSTALL_DIR}/available-plugins/$pluginName" "${JENV_ROOT}/plugins/$pluginName"
fi
done
fi
echo "$currentVersion" > "${JENV_ROOT}/jenv.version"
jenv doctor
[OK] No JAVA_HOME set
[OK] Java binaries in path are jenv shims
[OK] Jenv is correctly loaded
Any help, much appreciated.
I just experienced this same issue on mac- it was caused because for some reason the folder /Users/username/.jenv had become locked.
I couldn't find a way to unlock it, so i just copied it to another directory, then ran sudo rm -rf /Users/username/.jenv , copied it back, and that has solved the problem.
I can't figure out how to use the check_http module of Icinga to use a http proxy.
I tried to achieve this using the following entry in hosts.conf.
object Host "host.local.ch" {
import "generic-host"
address = "192.168.200.20"
vars.http_vhosts["http"] = {
http_uri = "/"
http_proxy = "127.0.0.1"
http_proxy_port = 5016
}
}
I found a script, edited it and create files for the example usage with Icinga, find it here:
https://github.com/ozzi-/icinga-check-http-proxy
Save the following script (/etc/icinga2/scripts/check_http_proxy.sh):
#!/bin/bash
# Author: ozzi- , forked from scott.liao (https://github.com/shazi7804/icinga-check-http-proxy)
# Description: ICINGA2 http check with proxy support
# startup checks
if [ -z "$BASH" ]; then
echo "Please use BASH."
exit 3
fi
if [ ! -e "/usr/bin/which" ]; then
echo "/usr/bin/which is missing."
exit 3
fi
wget=$(which wget)
if [ $? -ne 0 ]; then
echo "Please install wget."
exit 3
fi
# Default Values
ssl=""
useragent=""
host=""
port=""
proxy=""
url="/"
times=1
timeout=5
warning=700
critical=2000
certificate=""
bindaddress=""
#set system proxy from environment
getProxy() {
if [ -z "$1" ]; then
echo $http_proxy | awk -F'http://' '{print $2}'
else
echo $https_proxy | awk -F'http://' '{print $2}'
fi
}
# Usage Info
usage() {
echo '''Usage: check_http_proxy [OPTIONS]
[OPTIONS]:
-p PORT Port to connect to (default: 80)
-u URL URL path (default: /)
-H HOSTNAME Destination Hostname
-a USERAGENT Sends a useragent and mimics other request headers of a browser
-s Use HTTPS proxy (default connecting to proxy via http)
-P PROXY Sets the proxy ip:port (i.e. 127.0.0.1:8840)
-w WARNING warning threshold in milliseconds (default: 700)
-c CRITICAL Critical threshold in milliseconds (default: 2000)
-n TRIES Number of connection attempts (default: 1)
-t TIMEOUT Seconds to wait for connection (timeout) (default: 5)
-C CERTIFICATE Path to a client certificate (PEM and DER file types supported)
-b IP Bind address for wget (default: IP of primary networking interface)'''
}
# Check which threshold was reached
checkTime() {
if [ $1 -gt $critical ]; then
echo -n "CRITICAL"
elif [ $1 -gt $warning ]; then
echo -n "WARNING"
else
echo -n "OK"
fi
}
# Return code value
getStatus() {
if [ $1 -gt $critical ]; then
return 2
elif [ $1 -gt $warning ]; then
return 1
else
return 0
fi
}
#main
#get options
while getopts "c:p:s:a:w:u:P:H:n:t:C:b:" opt; do
case $opt in
c)
critical=$OPTARG
;;
p)
port=$OPTARG
;;
s)
ssl=1
;;
a)
useragent=$OPTARG
;;
w)
warning=$OPTARG
;;
u)
url=$OPTARG
;;
P)
proxy=$OPTARG
;;
H)
hostname=$OPTARG
;;
n)
times=$OPTARG
;;
t)
timeout=$OPTARG
;;
C)
client_certificate=$OPTARG
;;
b)
bindaddress=$OPTARG
;;
*)
usage
exit 3
;;
esac
done
#define host with last parameter
host=$hostname
#hostname is required
if [ -z "$host" ] || [ $# -eq 0 ]; then
echo "Error: host is required"
usage
exit 3
fi
#set proxy from environment if available and no proxy option is given
if [ -z "$proxy" ]; then
proxy="$(getProxy ssl)"
fi
#use ssl or not
if [ -z "$ssl" ]; then
header="HTTP"
proxy_cmd="http_proxy=$proxy"
url_prefix="http://"
else
header="HTTPS"
proxy_cmd="https_proxy=$proxy"
url_prefix="https://"
fi
#different port
if [ -z "$port" ]; then
url="${url_prefix}${host}${url}"
else
url="${url_prefix}${host}:${port}${url}"
fi
start=$(echo $(($(date +%s%N)/1000000)))
if [ -z "$useragent" ]; then
if [ -z "$client_certificate" ]; then
#execute and capture execution time and return status of wget
$wget -t $times --timeout $timeout -O /dev/null -q -e $proxy_cmd --bind-address=${bindaddress} $url
status=$?
elif [ -n "$client_certificate" ]; then
#execute and capture execution time and return status of wget with client certificate
$wget -t $times --timeout $timeout -O /dev/null -q -e $proxy_cmd --bind-address=${bindaddress} --certificate=$client_certificate $url
status=$?
fi
else
if [ -n "$client_certificate" ]; then
$wget -t $times --timeout $timeout -O /dev/null -q -e $proxy_cmd --bind-address=${bindaddress} --certificate=$client_certificate $url \
--header="User-Agent: $useragent" \
--header="Accept: image/png,image/*;q=0.8,*/*;q=0.5" \
--header="Accept-Language: en-us,en;q=0.5" \
--header="Accept-Encoding: gzip, deflate"
status=$?
else
#execute with fake user agent and capture execution time and return status of wget
$wget -t $times --timeout $timeout -O /dev/null -q -e $proxy_cmd --bind-address=${bindaddress} $url \
--header="User-Agent: $useragent" \
--header="Accept: image/png,image/*;q=0.8,*/*;q=0.5" \
--header="Accept-Language: en-us,en;q=0.5" \
--header="Accept-Encoding: gzip, deflate"
status=$?
fi
fi
end=$(echo $(($(date +%s%N)/1000000)))
#decide output by return code
if [ $status -eq 0 ] ; then
echo "${header} $(checkTime $((end - start))): $((end - start))ms - ${url}|time=$((end - start))ms;${warning};${critical};0;"
getStatus $((end - start))
exit $?
else
case $status in
1)
echo "${header} CRITICAL: Generic error code ($status) - ${url}"
;;
2)
echo "${header} CRITICAL: Parse error ($status) - ${url}"
;;
3)
echo "${header} CRITICAL: File I/O error ($status) - ${url}"
;;
4)
echo "${header} CRITICAL: Network failure ($status) - ${url}"
;;
5)
echo "${header} CRITICAL: SSL verification failure ($status) - ${url}"
;;
6)
echo "${header} CRITICAL: Authentication failure ($status) - ${url}"
;;
7)
echo "${header} CRITICAL: Protocol errors ($status) - ${url}"
;;
8)
echo "${header} CRITICAL: Server issued an error response ($status) - ${url}"
;;
*)
echo "${header} UNKNOWN: $status - ${url}"
exit 3
;;
esac
exit 2
fi
Icinga command definition (/etc/icinga2/conf.d/commands.conf):
object CheckCommand "check-http-proxy" {
command = [ ConfigDir + "/scripts/check_http_proxy.sh" ]
arguments += {
"-p" = {
value = "$chp_port$"
description = "Port to connect to (default: 80)"
}
"-u" = {
value = "$chp_url$"
description = "URL path (default: /)"
}
"-H" = {
required = true
value = "$chp_hostname$"
description = "Destination Hostname"
}
"-s" = {
value = "$chp_ssl$"
description = "Use HTTPS proxy (default: http proxy)"
}
"-P" = {
required = true
value = "$chvp_proxy$"
description = "Sets the proxy ip:port (i.e. 127.0.0.1:8840)"
}
"-a" = {
value = "$chp_useragent$"
description = "Sends a useragent and mimics other request headers of a browser"
}
"-w" = {
value = "$chp_warning_timeout$"
description = "Warning threshold in milliseconds (default: 700)"
}
"-c" = {
value = "$chp_critical_timeout$"
description = "Critical threshold in milliseconds (default: 2000)"
}
"-b" = {
value = "$chp_bind_adr$"
description = "Bind address for wget (default: IP of primary networking interface)"
}
"-n" = {
value = "$chp_tries$"
description = "Number of connection attempts (default: 1)"
}
"-t" = {
value = "$chp_timeout$"
description = "Seconds to wait for connection (timeout) (default: 5)"
}
"-C" = {
value = "$chp_certificate$"
description = "Path to a client certificate (PEM and DER file types supported)"
}
}
}
Usage in /etc/icinga2/conf.d/hosts.conf
object Host "sub.domain.ch" {
check_command = "check-http-proxy"
vars.chp_hostname = "sub.domain.ch"
vars.chp_proxy = "127.0.0.1:5016"
}
I configured WP_UnitTestCase and the wp_cli and PHPUnit with composer in PHPStorm. I had an issue where it couldn’t find/use my WP DB username and password to create the DB so I created it manually in the terminal. (was this a mistake?) install-wp-tests.sh the installed, I was able to run some test did a bit of development and then shutdown my machine.
The next day, I started up my machine and attempted to continue where I left off. However PHPunit (should I be calling this WP_UnitTestCase instead?) Failed to run with the following errors.
Warning: require_once(/tmp/wordpress-tests-lib/includes/functions.php): failed to >open stream: No such file or directory in /thefullpathtowordpressprojectd/wp->content/plugins/myplugin/tests/bootstrap.php on line 8
Well /tmp/wordpress-tests-lib/ doesn’t exist
So I look into the install-wp-tests.sh and its installing itself to a tmp directory…okay?! (So ok I did notice that phpunit said Installing when I ran my tests the night before… so it reinstalls itself for every test!?)
Then I re-run ‘install-wp-tests.sh’, it fails when attempting to create the ‘wordpress-tests’ db since it already exist but I can now run tests again.
My question is even if the scaffolding/ WP_UnitTestCase reinstalls itself every time I run phpunit in the directory of my plugin folder where my phpunit.xml is. What do I have to change in the ‘install-wp-tests.sh’ or phpunit.xml so I don't have to manually reinstall for an existing project, how to clear the require_once error for the tmp empty directory?
Should I have to reinstall it everytime I reopen my project?
my install-we-test.sh is unchanged, but here it is:
#!/usr/bin/env bash
if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
exit 1
fi
DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
set -ex
download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}
install_wp() {
if [ -d $WP_CORE_DIR ]; then
return;
fi
mkdir -p $WP_CORE_DIR
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}
install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi
# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ $WP_TESTS_DIR/includes
fi
cd $WP_TESTS_DIR
if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi
}
install_db() {
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""
if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi
# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}
install_wp
install_test_suite
install_db
and my phpunit.xml
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
I have an init.d script to start my process on boot and requires networking to be initialized. I can use utility nm-online which comes with NetworkManager package but problem will be at deployment where NW will be not installed so I have to have some other reliable option which can tell me network is set and I can connect to other server over network. I can keep trying till I get the networking up or connection is set but that will cause some other problem related to error reporting.
Here is the similar question asked for some other folk.
How to detect when networking initialized in /etc/init.d script?
wait_for_network()
{
[ -z "${LINKDELAY}" ] && LINKDELAY=10
$INFO "Waiting for network..."
if [ -f /usr/sbin/nm-online ]; then
nm-online -q --timeout=$LINKDELAY || nm-online -q -x --timeout=30
else
check_for_network_up $LINKDELAY || check_for_network_up 30
fi
[ "$?" = "0" ] && success "network startup" || failure "network startup"
echo
}
I was trying some other approach where I can check for route table. If network is not up, route command return zero entry but problem is I don’t know real number of route entry. It could be two on one machine where 10 on other machine.
check_for_network_up_old3() {
let no_of_routes=`/bin/netstat -rn | wc -l`
$INFO "netstat result $?"
timeout=$1
while [ "$timeout" != "0" ]; do
let routes=`/sbin/ip route show | wc -l`
$INFO "$routes"
if [ $routes -gt 1 ]; then
return 0
fi
timeout=$((timeout-1))
sleep 1
$INFO "check_for_network_up $timeout"
done
return 1
}
I am working through this tutorial on daemonizing php scripts. When I run the following Unix command:
. /etc/init.d/functions
#startup values
log=/var/log/Daemon.log
#verify that the executable exists
test -x /home/godlikemouse/Daemon.php || exit 0RETVAL=0
prog="Daemon"
proc=/var/lock/subsys/Daemon
bin=/home/godlikemouse/Daemon.php
start() {
# Check if Daemon is already running
if [ ! -f $proc ]; then
echo -n $"Starting $prog: "
daemon $bin --log=$log
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $proc
echo
fi
return $RETVAL
}
I get the following output:
./Daemon: line 12: /etc/init.d/functions: No such file or directory
Starting Daemon: daemon: unrecognized option `--log=/var/log/Daemon.log'
I looked at my file system and there was no /etc/init.d file. Can anyone tell me what this is and where to obtain it? Also is the absence of that file what's causing the other error?
Separate your args within their own " " double-quotes:
args="--node $prog"
daemon "nohup ${exe}" "$args &" </dev/null 2>/dev/null
daemon "exe" "args"