├── .gitignore ├── tests ├── inventory.yml ├── integration-tests.yml ├── Vagrantfile └── deploy-nginx.yml ├── .travis.yml ├── changelog.md ├── README.md └── nginx /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | *sublime* 3 | -------------------------------------------------------------------------------- /tests/inventory.yml: -------------------------------------------------------------------------------- 1 | [nodes] 2 | node1 ansible_ssh_port=22 ansible_ssh_host=172.16.1.10 3 | -------------------------------------------------------------------------------- /tests/integration-tests.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # 3 | # integration-tests.yml 4 | # 5 | 6 | - hosts: all 7 | sudo: True 8 | tasks: 9 | # Tests 10 | - name: Start nginx 11 | service: name=nginx state=started 12 | - name: Check if nginx service is started 13 | shell: "ps aux | grep '[n]ginx: master process'" 14 | - name: Check for 200 response from nginx 15 | shell: "curl -Is http://localhost | grep '200 OK'" 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | 5 | env: 6 | - SITE=deploy-nginx.yml 7 | 8 | before_install: 9 | - sudo apt-get update -qq 10 | - sudo apt-get install curl -y 11 | 12 | install: 13 | - pip install -U ansible 14 | 15 | script: 16 | - "ansible-playbook -i tests/inventory.yml tests/$SITE --syntax-check" 17 | 18 | - "ansible-playbook -i tests/inventory.yml tests/deploy-nginx.yml --connection=local --sudo -vvvv" 19 | 20 | - "ansible-playbook -i tests/inventory.yml tests/integration-tests.yml --connection=local --sudo -vvvv" -------------------------------------------------------------------------------- /tests/Vagrantfile: -------------------------------------------------------------------------------- 1 | # 2 | # Vagrantfile 3 | # 4 | 5 | Vagrant.configure('2') do |config| 6 | 7 | config.vm.define 'test-node' do |instance| 8 | 9 | # Make sure to download as 'ubuntu-14.10' 10 | # vagrant box add ubuntu-14.10 https://cloud-images.ubuntu.com/vagrant/utopic/current/utopic-server-cloudimg-amd64-vagrant-disk1.box 11 | 12 | instance.vm.box = 'ubuntu-14.10' 13 | instance.vm.host_name = 'test-node' 14 | instance.vm.network 'private_network', ip: '172.16.1.10' 15 | 16 | instance.vm.provision 'ansible' do |prov| 17 | # prov.inventory_path = 'inventory.yml' 18 | prov.playbook = 'deploy-nginx.yml' 19 | # prov.playbook = 'integration-tests.yml' # to run only the tests 20 | prov.verbose = 'vvvv' 21 | end # prov 22 | end # instance 23 | 24 | end # config 25 | -------------------------------------------------------------------------------- /tests/deploy-nginx.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # 4 | # nginx-init-ubuntu install 5 | # 6 | # Warning, do not use this as a production ansible playbook. 7 | # A production one is pending. This is only for testing. 8 | # 9 | 10 | - hosts: all 11 | sudo: True 12 | vars: 13 | nginx_version: "1.7.9" 14 | nginx_download_file: "nginx-{{nginx_version}}.tar.gz" 15 | nginx_install_dir: /tmp/nginx-install 16 | handlers: 17 | - name: start nginx 18 | command: service nginx start 19 | tasks: 20 | - file: path={{nginx_install_dir}} state=directory 21 | - apt: pkg={{item}} state=present update_cache=yes 22 | with_items: 23 | - libpcre3-dev 24 | - zlib1g-dev 25 | - get_url: url=http://nginx.org/download/{{nginx_download_file}} dest={{nginx_install_dir}} 26 | - copy: src=../nginx dest=/etc/init.d/nginx force=yes mode=755 owner=root group=root 27 | - command: tar -xvf {{nginx_download_file}} chdir={{nginx_install_dir}} 28 | - name: Compile and install 29 | shell: ./configure && make && make install chdir="{{nginx_install_dir}}/nginx-{{nginx_version}}" 30 | notify: start nginx 31 | 32 | - include: integration-tests.yml 33 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # nginx-init-ubuntu 2 | 3 | * v3.9.0 4 | - Update documentation to reference v1.7.9 (@v3.9.0-beta), Fixes #27, #19. 5 | 6 | * v3.8.0 7 | - Add better defaults handling by changing source order and using default values 8 | - Add travis file 9 | - Add Travis banner 10 | 11 | * v3.7.0 12 | - Missing reload action from service (@violuke), Fixes #15 13 | - Add NGINXPATH var (@mattbearman), Fixes #14 14 | - Version bump 15 | 16 | * v3.6.0 - Testing framework, simple deployment script, Fix #8 17 | - Add Vagrantfile 18 | - Add `deploy-nginx.yml` which is a simple ansible deployment script 19 | - Add `integration-tests.yml` which check for service and response 20 | - Add `.gitignore` entry for `.vagrant` 21 | - Fix #8 - Error return code now correctly returns when nginx fails to start 22 | 23 | * v3.5.1 - Fix #2, part 2 24 | - Add `log_end_msg` repr (back) for friendly display but make exit codes proper 25 | - Add exit codes at eos 26 | - Modify `reload` to properly do send `kill -HUP` like in `quietupgrade` 27 | 28 | * v3.5.0 - Fix #2 29 | - Fix sample install instructions 30 | - Fix var for quiet upgrade 31 | - Update documentation with 1.4.3 compatibility 32 | - Add additional lsb logging 33 | - Add error codes for `status`, `terminate`, `start`, `stop`, `reload`, `quietupgrade`, `destroy` 34 | 35 | * v?.?.? 36 | - check git commit history :-) 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nginx-init-ubuntu 2 | ================= 3 | 4 | 5 | ## Status 6 | 7 | [![Build Status](https://travis-ci.org/JasonGiedymin/nginx-init-ubuntu.svg?branch=master)](https://travis-ci.org/JasonGiedymin/nginx-init-ubuntu) 8 | 9 | Current release: [v3.9.0](https://github.com/JasonGiedymin/nginx-init-ubuntu/releases/tag/v3.9.0) 10 | 11 | Previous stable release [v3.8.0](https://github.com/JasonGiedymin/nginx-init-ubuntu/releases/tag/v3.8.0) 12 | 13 | Notes: v3.8.0 has been stable for the last several months without issues. v3.9.0 while 14 | stable, is new. 15 | 16 | ## Info 17 | 18 | Tried and true Nginx init script. 19 | 20 | Ubuntu, Vagrant, and [Docker](https://github.com/AnsibleShipyard/ansible-nginx/blob/master/Dockerfile) tested! 21 | 22 | You may also want to use the [AnsibleShipyard ansible-nginx playbook](https://github.com/AnsibleShipyard/ansible-nginx). 23 | 24 | Simple ansible playbook sits in this repository. 25 | 26 | Author: [Jason Giedymin](http://jasongiedymin.com) 27 | 28 | Check out my other [repos](http://github.com/JasonGiedymin)! 29 | 30 | 31 | ## Support 32 | 33 | Rest assured that this repo will be maintained _indefinitely_ beyond Ubuntu LTS 34 | and systemd adoption into Ubuntu stable. 35 | 36 | 37 | ## Last tested with: 38 | 39 | 1. Ubuntu 14.xx (works with prior versions) 40 | 2. [nginx-1.7.9](http://nginx.org/download/nginx-1.7.9.tar.gz) (works with prior versions) 41 | 42 | 43 | ## Notes ## 44 | It is recommended to install [Nginx](http://nginx.net/) by doing a full compile & build. Not all package repositories keep their branches updated. For security it is your duty to maintain a good working environment and thus includes all interfacing applications. 45 | This script works turn-key with the default compile of nginx. It is fully recommended that you go through the variables contained within this script if you have a custom compiled build. 46 | 47 | A great resource is the [Nginx Wiki](http://wiki.nginx.org/). 48 | 49 | 50 | ## Basic Install ## 51 | Basic install instructions, use sudo if necessary for the below (depends on your setup/security). 52 | 53 | # [optional as you may have these installed] 54 | sudo apt-get install libpcre3-dev zlib1g-dev 55 | 56 | mkdir -p ~/temp/nginx-install 57 | cd ~/temp/nginx-install 58 | 59 | # download/curl/wget nginx 60 | wget http://nginx.org/download/nginx-1.7.9.tar.gz 61 | tar -xvf nginx-1.7.9.tar.gz 62 | cd nginx-1.7.9/ 63 | ./configure 64 | make 65 | sudo make install 66 | 67 | #copy/download/curl/wget the init script 68 | sudo wget https://raw.githubusercontent.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx 69 | sudo chmod +x /etc/init.d/nginx 70 | 71 | service nginx status # to poll for current status 72 | service nginx stop # to stop any servers if any 73 | service nginx start # to start the server 74 | 75 | #[optional] 76 | sudo update-rc.d -f nginx defaults 77 | 78 | #[optional remove the upstart script] 79 | sudo update-rc.d -f nginx remove 80 | 81 | 82 | ## Advanced Configuration ## 83 | If you need to override the values within the script you should use `/etc/default/nginx`. 84 | 85 | You can override any of these values: 86 | 87 | | Variable | Function | 88 | | ------------- |-------------| 89 | | PATH | Path environment variable 90 | | NGINXPATH | Root path where installed 91 | | DAEMON | Path to Deamon binary 92 | | PS | Process name 93 | | PIDNAME | Lets you do $PS-slave 94 | | PIDFILE | Pid file 95 | | PIDSPATH | Default PID location 96 | | DESCRIPTION | Process description 97 | | RUNAS | User to run as 98 | | NGINX_CONF_FILE | Config file path 99 | 100 | For instance, if you needed to change the description of the server during logging: 101 | 102 | # Edit [/etc/default/nginx] and add the below line 103 | DESCRIPTION="My Awesome Nginx Server..." 104 | 105 | # Next run the below command: 106 | sudo service nginx restart 107 | 108 | # Output of running restart with nginx defaults file: 109 | * Stopping My Super Nginx Server... [ OK ] 110 | * Starting My Super Nginx Server... [ OK ] 111 | 112 | # Notice that is says "My Super Nginx Server..." as opposed to the default 113 | # "Nginx Server...". 114 | 115 | The NGINXPATH value should point to your installation of Nginx, the default is /usr/local/nginx 116 | 117 | It's likely you'll need to update the NGINXPATH value if you didn't install from source. Eg, if you install Nginx using apt-get on Ubuntu nginx will be installed to /etc/nginx 118 | 119 | # Changing NGINXPATH when Nginx was installed with apt-get 120 | NGINXPATH=/etc/nginx 121 | 122 | 123 | ## Testing 124 | Tests run as part of the deployment scripts `integration-tests.yml`. 125 | 126 | To start make sure you have [vagrant](http://vagrantup.com), and [ansible](https://github.com/ansible/ansible) installed. 127 | 128 | Download the Ubuntu base box: 129 | 130 | ```bash 131 | vagrant box add ubuntu-14.10 https://cloud-images.ubuntu.com/vagrant/utopic/current/utopic-server-cloudimg-amd64-vagrant-disk1.box 132 | ``` 133 | 134 | Run vagrant: 135 | 136 | vagrant up 137 | 138 | Manually provision again: 139 | 140 | vagrant provision 141 | 142 | ### Using with Docker 143 | A basic Dockerfile will arrive shortly for testing, but note that I focued my efforts on creating an nginx [ansible role](https://github.com/AnsibleShipyard/ansible-nginx). [This repo](https://github.com/AnsibleShipyard/ansible-nginx) has a [Dockerfile](https://github.com/AnsibleShipyard/ansible-nginx/blob/master/Dockerfile) which will install Nginx along with `nginx-init-ubuntu` (this repo) using ansible. Until the basic testing Dockerfile is in place here please refer to the [ansible role](https://github.com/AnsibleShipyard/ansible-nginx) and it's [Dockerfile](https://github.com/AnsibleShipyard/ansible-nginx/blob/master/Dockerfile) -- if your looking for stability. 144 | 145 | If your looking for a more production and developer friendly [Dockerfile, look here](https://github.com/AnsibleShipyard/ansible-nginx/blob/master/Dockerfile). 146 | 147 | When using the ansible role mentioned above you will need to set `nginx_docker_override` to `True` as the role will detect if running within a Dockerfile. This is to prevent nginx running in `daemon` mode. 148 | 149 | A copy of [nginx-init-ubuntu](https://github.com/JasonGiedymin/nginx-init-ubuntu) is present in the [ansible role](https://github.com/AnsibleShipyard/ansible-nginx). 150 | 151 | ## Contributions ## 152 | _Contributions are welcome!_ 153 | -------------------------------------------------------------------------------- /nginx: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: nginx 4 | # Required-Start: $remote_fs $syslog 5 | # Required-Stop: $remote_fs $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: nginx init.d dash script for Ubuntu or other *nix. 9 | # Description: nginx init.d dash script for Ubuntu or other *nix. 10 | ### END INIT INFO 11 | #------------------------------------------------------------------------------ 12 | # nginx - this Debian Almquist shell (dash) script, starts and stops the nginx 13 | # daemon for Ubuntu and other *nix releases. 14 | # 15 | # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 16 | # proxy and IMAP/POP3 proxy server. This \ 17 | # script will manage the initiation of the \ 18 | # server and it's process state. 19 | # 20 | # processname: nginx 21 | # config: /usr/local/nginx/conf/nginx.conf 22 | # pidfile: /usr/local/nginx/logs/nginx.pid 23 | # Provides: nginx 24 | # 25 | # Author: Jason Giedymin 26 | # . 27 | # 28 | # Version: 3.9.0 12-MAY-2015 jason.giedymin AT gmail.com 29 | # Notes: nginx init.d dash script for Ubuntu. 30 | # Tested with: Ubuntu 14.10, nginx-1.7.9 31 | # 32 | # This script's project home is: 33 | # http://github.com/JasonGiedymin/nginx-init-ubuntu 34 | # 35 | #------------------------------------------------------------------------------ 36 | # MIT X11 License 37 | #------------------------------------------------------------------------------ 38 | # 39 | # Copyright (c) 2008-2013 Jason Giedymin, http://jasongiedymin.com 40 | # 41 | # Permission is hereby granted, free of charge, to any person obtaining 42 | # a copy of this software and associated documentation files (the 43 | # "Software"), to deal in the Software without restriction, including 44 | # without limitation the rights to use, copy, modify, merge, publish, 45 | # distribute, sublicense, and/or sell copies of the Software, and to 46 | # permit persons to whom the Software is furnished to do so, subject to 47 | # the following conditions: 48 | # 49 | # The above copyright notice and this permission notice shall be 50 | # included in all copies or substantial portions of the Software. 51 | # 52 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 53 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 54 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 55 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 56 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 57 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 58 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 59 | #------------------------------------------------------------------------------ 60 | 61 | #------------------------------------------------------------------------------ 62 | # Functions 63 | #------------------------------------------------------------------------------ 64 | LSB_FUNC=/lib/lsb/init-functions 65 | 66 | # Test that init functions exists 67 | test -r $LSB_FUNC || { 68 | echo "$0: Cannot find $LSB_FUNC! Script exiting." 1>&2 69 | exit 5 70 | } 71 | 72 | . $LSB_FUNC 73 | 74 | #------------------------------------------------------------------------------ 75 | # Consts 76 | #------------------------------------------------------------------------------ 77 | # Include nginx defaults if available 78 | if [ -f /etc/default/nginx ]; then 79 | . /etc/default/nginx 80 | fi 81 | 82 | # Minimize path 83 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 84 | 85 | PS=${PS:-"nginx"} # process name 86 | DESCRIPTION=${DESCRIPTION:-"Nginx Server..."} # process description 87 | NGINXPATH=${NGINXPATH:-/usr/local/nginx} # root path where installed 88 | DAEMON=${DAEMON:-$NGINXPATH/sbin/nginx} # path to daemon binary 89 | NGINX_CONF_FILE=${NGINX_CONF_FILE:-$NGINXPATH/conf/nginx.conf} # config file path 90 | 91 | PIDNAME=${PIDNAME:-"nginx"} # lets you do $PS-slave 92 | PIDFILE=${PIDFILE:-$PIDNAME.pid} # pid file 93 | PIDSPATH=${PIDSPATH:-$NGINXPATH/logs} # default pid location, you should change it 94 | RUNAS=${RUNAS:-root} # user to run as 95 | 96 | SCRIPT_OK=0 # ala error codes 97 | SCRIPT_ERROR=1 # ala error codes 98 | TRUE=1 # boolean 99 | FALSE=0 # boolean 100 | 101 | #------------------------------------------------------------------------------ 102 | # Simple Tests 103 | #------------------------------------------------------------------------------ 104 | 105 | # Test if nginx is a file and executable 106 | test -x $DAEMON || { 107 | echo "$0: You don't have permissions to execute nginx." 1>&2 108 | exit 4 109 | } 110 | 111 | # You can also set your conditions like so: 112 | # set exit condition 113 | # set -e 114 | 115 | #------------------------------------------------------------------------------ 116 | # Functions 117 | #------------------------------------------------------------------------------ 118 | 119 | setFilePerms(){ 120 | if [ -f $PIDSPATH/$PIDFILE ]; then 121 | chmod 400 $PIDSPATH/$PIDFILE 122 | fi 123 | } 124 | 125 | configtest() { 126 | $DAEMON -t -c $NGINX_CONF_FILE 127 | } 128 | 129 | getPSCount() { 130 | return `pgrep -f $PS | wc -l` 131 | } 132 | 133 | isRunning() { 134 | if [ $1 ]; then 135 | pidof_daemon $1 136 | PID=$? 137 | 138 | if [ $PID -gt 0 ]; then 139 | return 1 140 | else 141 | return 0 142 | fi 143 | else 144 | pidof_daemon 145 | PID=$? 146 | 147 | if [ $PID -gt 0 ]; then 148 | return 1 149 | else 150 | return 0 151 | fi 152 | fi 153 | } 154 | 155 | #courtesy of php-fpm 156 | wait_for_pid () { 157 | try=0 158 | 159 | while test $try -lt 35 ; do 160 | case "$1" in 161 | 'created') 162 | if [ -f "$2" ]; then 163 | try='' 164 | break 165 | fi 166 | ;; 167 | 168 | 'removed') 169 | if [ ! -f "$2" ]; then 170 | try='' 171 | break 172 | fi 173 | ;; 174 | esac 175 | 176 | try=`expr $try + 1` 177 | sleep 1 178 | done 179 | } 180 | 181 | status(){ 182 | isRunning 183 | isAlive=$? 184 | 185 | if [ "${isAlive}" -eq $TRUE ]; then 186 | log_warning_msg "$DESCRIPTION found running with processes: `pidof $PS`" 187 | rc=0 188 | else 189 | log_warning_msg "$DESCRIPTION is NOT running." 190 | rc=3 191 | fi 192 | 193 | return 194 | } 195 | 196 | removePIDFile(){ 197 | if [ $1 ]; then 198 | if [ -f $1 ]; then 199 | rm -f $1 200 | fi 201 | else 202 | #Do default removal 203 | if [ -f $PIDSPATH/$PIDFILE ]; then 204 | rm -f $PIDSPATH/$PIDFILE 205 | fi 206 | fi 207 | } 208 | 209 | start() { 210 | log_daemon_msg "Starting $DESCRIPTION" 211 | 212 | isRunning 213 | isAlive=$? 214 | 215 | if [ "${isAlive}" -eq $TRUE ]; then 216 | log_end_msg $SCRIPT_ERROR 217 | rc=0 218 | else 219 | start-stop-daemon --start --quiet --chuid \ 220 | $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \ 221 | -- -c $NGINX_CONF_FILE 222 | status=$? 223 | setFilePerms 224 | 225 | if [ "${status}" -eq 0 ]; then 226 | log_end_msg $SCRIPT_OK 227 | rc=0 228 | else 229 | log_end_msg $SCRIPT_ERROR 230 | rc=7 231 | fi 232 | fi 233 | 234 | return 235 | } 236 | 237 | stop() { 238 | log_daemon_msg "Stopping $DESCRIPTION" 239 | 240 | isRunning 241 | isAlive=$? 242 | 243 | if [ "${isAlive}" -eq $TRUE ]; then 244 | start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE 245 | 246 | wait_for_pid 'removed' $PIDSPATH/$PIDFILE 247 | 248 | if [ -n "$try" ]; then 249 | log_end_msg $SCRIPT_ERROR 250 | rc=0 # lsb states 1, but under status it is 2 (which is more prescriptive). Deferring to standard. 251 | else 252 | removePIDFile 253 | log_end_msg $SCRIPT_OK 254 | rc=0 255 | fi 256 | else 257 | log_end_msg $SCRIPT_ERROR 258 | rc=7 259 | fi 260 | 261 | return 262 | } 263 | 264 | reload() { 265 | configtest || return $? 266 | 267 | log_daemon_msg "Reloading (via HUP) $DESCRIPTION" 268 | 269 | isRunning 270 | 271 | if [ $? -eq $TRUE ]; then 272 | kill -HUP `cat $PIDSPATH/$PIDFILE` 273 | log_end_msg $SCRIPT_OK 274 | rc=0 275 | else 276 | log_end_msg $SCRIPT_ERROR 277 | rc=7 278 | fi 279 | 280 | return 281 | } 282 | 283 | quietupgrade() { 284 | log_daemon_msg "Peforming Quiet Upgrade $DESCRIPTION" 285 | 286 | isRunning 287 | isAlive=$? 288 | 289 | if [ "${isAlive}" -eq $TRUE ]; then 290 | kill -USR2 `cat $PIDSPATH/$PIDFILE` 291 | kill -WINCH `cat $PIDSPATH/$PIDFILE.oldbin` 292 | 293 | isRunning 294 | isAlive=$? 295 | 296 | if [ "${isAlive}" -eq $TRUE ]; then 297 | kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin` 298 | wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin 299 | removePIDFile $PIDSPATH/$PIDFILE.oldbin 300 | 301 | log_end_msg $SCRIPT_OK 302 | rc=0 303 | else 304 | log_end_msg $SCRIPT_ERROR 305 | 306 | log_daemon_msg "ERROR! Reverting back to original $DESCRIPTION" 307 | 308 | kill -HUP `cat $PIDSPATH/$PIDFILE` 309 | kill -TERM `cat $PIDSPATH/$PIDFILE.oldbin` 310 | kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin` 311 | 312 | wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin 313 | removePIDFile $PIDSPATH/$PIDFILE.oldbin 314 | 315 | log_end_msg $SCRIPT_OK 316 | rc=0 317 | fi 318 | else 319 | log_end_msg $SCRIPT_ERROR 320 | rc=7 321 | fi 322 | 323 | return 324 | } 325 | 326 | terminate() { 327 | log_daemon_msg "Force terminating (via KILL) $DESCRIPTION" 328 | 329 | PIDS=`pidof $PS` || true 330 | 331 | [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE` 332 | 333 | for i in $PIDS; do 334 | if [ "$i" = "$PIDS2" ]; then 335 | kill $i 336 | wait_for_pid 'removed' $PIDSPATH/$PIDFILE 337 | removePIDFile 338 | fi 339 | done 340 | 341 | log_end_msg $SCRIPT_OK 342 | rc=0 343 | } 344 | 345 | destroy() { 346 | log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION" 347 | killall $PS -q >> /dev/null 2>&1 348 | log_end_msg $SCRIPT_OK 349 | rc=0 350 | } 351 | 352 | pidof_daemon() { 353 | PIDS=`pidof $PS` || true 354 | 355 | [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE` 356 | 357 | for i in $PIDS; do 358 | if [ "$i" = "$PIDS2" ]; then 359 | return 1 360 | fi 361 | done 362 | 363 | return 0 364 | } 365 | 366 | action="$1" 367 | case "$1" in 368 | start) 369 | start 370 | ;; 371 | stop) 372 | stop 373 | ;; 374 | restart|force-reload) 375 | stop 376 | # if [ $rc -ne 0 ]; then 377 | # script_exit 378 | # fi 379 | sleep 1 380 | start 381 | ;; 382 | reload) 383 | $1 384 | ;; 385 | status) 386 | status 387 | ;; 388 | configtest) 389 | $1 390 | ;; 391 | quietupgrade) 392 | $1 393 | ;; 394 | terminate) 395 | $1 396 | ;; 397 | destroy) 398 | $1 399 | ;; 400 | *) 401 | FULLPATH=/etc/init.d/$PS 402 | echo "Usage: $FULLPATH {start|stop|restart|force-reload|reload|status|configtest|quietupgrade|terminate|destroy}" 403 | echo " The 'destroy' command should only be used as a last resort." 404 | exit 3 405 | ;; 406 | esac 407 | 408 | exit $rc 409 | --------------------------------------------------------------------------------