Linux 以普通用户自启动服务

Posted by wxianfeng Fri, 26 Oct 2012 18:52:00 GMT

linux 自启动服务 默认是以root启动的, 但是我们很多服务都是以普通用户启动的, 如果以root启动 , 这样会到来一些权限问题,例如应用中保存的文件等等.

以普通用户启动的核心指令如下:

su - user -f /path/shell

demo:

/etc/rc.local

[wxianfeng@li390-146 ~]$ cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

/bin/sh /usr/local/system/www/shell/linode/init_by_root.sh >> /usr/local/system/logs/init.log 2>&1
su - wxianfeng -f /usr/local/system/www/shell/linode/init_by_wxianfeng.sh >> /usr/local/system/logs/init.log 2>&1

init_by_root.sh 脚本

#!/bin/bash 

# nginx
/usr/local/system/nginx/sbin/nginx

# mysql
/etc/init.d/mysqld start

# svn
svnserve -d -r /usr/local/system/vcs

init_by_wxianfeng.sh 脚本

#!/bin/bash

source /usr/local/rvm/environments/ruby-1.9.2-p180

cd /usr/local/system/www/project_manager

thin start -e production -d -p 5000

source /usr/local/rvm/environments/ruby-1.8.7-p334 

thin start -C /etc/thin/thin.yml

This entry was posted on Fri, 26 Oct 2012 18:52:00 GMT and Posted in , . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags ,


Trackbacks

Use the following link to trackback from your own site:
http://wxianfeng.com/trackbacks?article_id=246

Comments

Leave a comment