Linux services can be started, stopped and reloaded with the use of scripts stocked in /etc/init.d/.
However, during start up or when changing runlevel, those scripts are searched in /etc/rcX.d/ where X is the runlevel number.
This tutorial will explain how one can activate, deactivate or modify a service start up.
When installing a new service under debian, the default is to enable it. So for instance, if you just installed apache2 package, after you installed it, apache service will be started and so will it be upon the next reboots.
If you do not use apache all the time, you might want to disable this service from starting up upon boot up and simply start it manually when you actually need it by running this command:
1
/etc/init.d/apache2 start
You could either disable this service on boot up by removing any symbolic links in /etc/rcX.d/SYYapache2 or by using update-rc.d.
The advantage of using update-rc.d is that it will take care of removing/adding any required links to /etc/init.d automatically.
Taking apache2 as an example, let’s examine how /etc/rcX.d is looking like:
As you can see, for runlevels 0, 1 and 6 there is a K at the beginning of the link, for runlevels 2, 3, 4 and 5, there is a S. Those two letters stands for Kill and Start.
On Debian and Ubuntu, runlevels 2, 3, 4 and 5 are multi-users runlevels.
Runlevel 0 is Halt.
Runlevel 1 is single user mode
Runlevel 6 is reboot
1. Removing A Service
If you want to totally disable apache2 service by hand, you would need to delete every single link in /etc/rcX.d/. Using update-rc.d it is as simple as:
1
update-rc.d -f apache2 remove
The use of -f is to force the removal of the symlinks even if there is still /etc/init.d/apache2.
Note: This command will only disable the service until next time the service is upgraded. If you want to make sure the service won't be re-enabled upon upgrade, you should also type the following:
# update-rc.d apache2 stop 80 0 1 2 3 4 5 6 .
2. Adding A Service
2.1. Default Priorities
Now, if you want to re-add this service to be started on boot up, you can simply use:
But as you can see, the default value is 20 which is pretty different than 91 … a S20 link is started before a S91 and and K91 is kill before K20.
To force apache2 to be started with priorities 91 for both Start and Kill, we need to use the following command:
Finally, if you only want to Start and Kill on specific runlevels, like for instance starting apache with priority 20 on runlevels 2, 3, 4 and 5 and Kill with priority 80 on runlevels 0, 1 and 6:
qichunren:bin qichunren$ ./rubyencoder
RubyEncoder 1.3 Evaluation (built: Aug 31 2010 11:55:25)
Copyright (c) 2008-2010 rubyencoder.com
Supports encoding for Ruby versions: 1.8.6,1.8.7,1.9.0,1.9.1,1.9.2
Usage, single file: rubyencoder [options] file.rb
multiple files: rubyencoder [options] file1.rb file2.rb file3.rb
file mask: rubyencoder [options] "*.rb"
file list: rubyencoder [options] @filelist
--ruby <version x.y> Encode for Ruby ver (1.8 default and/or 1.9)
* --expire <dd/mm/yyyy> Set script expiration date
* --days <nn> Set script expiration days (from today)
* --domain <domain> Bind script to domain name
* --domain-encrypt <domain> Bind and encrypt to domain name (one only)
* --ip <x.x.x.x[/y.y.y.y]> Bind script to ip/mask
* --ip-encrypt <x.x.x.x[/y.y.y.y]> Bind and encrypt to ip/mask (one only)
* --mac <x:x:x:x:x:x> Bind script to mac address
* --external <filename> Script will require license file to run
* --projid <value> Set project id (required for ext license)
* --projkey <value> Set project key (required for ext license)
* --time-server <server,server,...> Set time server (for expiration date check)
* script locking options are disabled for evaluation version
--const name=value Set custom defined constant
--catch err=function Set custom error handler
-p "code"|@file Prepend header code
-j "code"|@file Change default loader error code
-b <ext> Set file extension for backup files (bak is default)
-b- Disable backup of source files (be careful!)
-r Recurse subdirectories (use quotes for file masks)
-x "mask"|@list Exclude files from encoding
-f "mask"|@list Encode only these files
-o <output_dir> Specify output directory for encoded scripts
-w Wait for key press before exit
-q Display settings and request confirmation
-v Display version number
-l Display license information
-h Display this help
Hi,
Thank you for your interest in RubyEncoder. Please find answers below.
> 0. After I paid $159 for RubyEncoder, do I have license to run rubyencoder on different machines for different systems(mac or linux). I have serval machines for development and deployment.
RubyEncoder is licensed per-machine. One license lets you install and
use the encoder to one physical or virtual machine. If you use multiple
machines for development you may purchase additional licenses for $99
each. Note, loaders that are required to run protected files are free.
> 1. I developed on Mac OSX system usually, then deploy my rails application on Linux (Ubuntu 11). This goes well currently. I want to know after encode my rails 3 application on mac, then will it goes well on my deployed Linux machine?
Yes, you encode on your Mac and then install encoded files to your Linux
machine as usual. To run protected files on Linux you need to install
(copy a folder) RubyEncoder loaders for Linux to your rails root folder.
With version 1.3 you can encode your application controllers, helpers
and model rails files. Do not encode any other standard or configuration
rails files. For non-rails Ruby files you may encode any code. Ruby
verisons 1.8.6,1.8.7.1.9.0-1.9.3 are supported.
> 2. After I paid $159 for RubyEncoder, do I have to paid again for your update version? Can I get free follow-on support service and software update?
Once you pay you get 1 year of free support and updates.
> 3. How long is a paid license?
>
A license is time unlimited. Support is included for 1 year since the
date of purchase. We do email support.
Feel free to contact me if you have any further questions.
<?phpfunctionsmarty_block_users($params,$content,$smarty,&$repeat){if(empty($content)){if(empty($params['limit'])){$limit=10;}else{$limit=$params['limit'];}$CI=&get_instance();$GLOBALS['users']=$CI->db->query("select * from users order by created_at desc limit $limit")->result();}if(isset($GLOBALS['users'])!=NULL&&count($GLOBALS['users'])>0){$user=array_shift($GLOBALS['users']);$smarty->assign('user',$user);if(count($GLOBALS['users'])==0){unset($GLOBALS['users']);$repeat=false;}$repeat=true;}else{$repeat=false;}return$content;}?>
<?phpif(!defined('BASEPATH'))exit('No direct script access allowed');classDebugextendsMY_Controller{function__construct(){parent::__construct();// Write your own initialize code}functionindex(){$this->load->library('smarty');$this->smarty->assign("title","smarty template");$this->smarty->assign("body","欢迎使用smarty模板引擎");$arr=array(1=>'number 1',2=>'number 2',3=>'number 3');$this->smarty->assign("myarray",$arr);$this->smarty->display('index.html');}}
模板代码:
application/views/templates/index.html
12345678910111213141516
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>smarty模板使用示例</title></head><body><h1>{$title}</h1><p>{$body}</p><ul> {foreach from=$myarray item=v}
<li>{$v}</li> {/foreach}
</ul></body></html>
Rails framework and twitter bootstrap are good for your startup project, build-in generators generate source code by its way. It is a good starting point.
But I often have to change default generted source code:
Add encoding: utf-8 into ruby file header, for Ruby 1.9.2 encoding.
Change scaffold view files to apply bootstrap css.
Other things you want to override default templates.
Rails provides the mechanism to custom generator behavior.
I have already got it, and source code is on github, follow README for usage.
At huacnlee/ruby-china repository homepage, clicked “Fork” button, then after serval minutes, you will have you own forked repository copy.Then you clone to local.
1
git clone git@github.com:qichunren/ruby-china.git
Then you commit your changes, and push to it.When you found the original repository has some updated feature,you can do as follow:
ajax:before – right before ajax call
ajax:loading – before ajax call, but after XmlHttpRequest object is created)
ajax:success – successful ajax call
ajax:failure – failed ajax call
ajax:complete – completion of ajax call (after ajax:success and ajax:failure)
ajax:after – after ajax call is sent (note: not after it returns)