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

  1. Avatar
    Ηγουμενίτσα Ανκόνα about {{count}} years ago:

    Hello! I could have sworn I’ve been tto this website before but after
    browsng through many of the posts I realized it’s new
    to me. Regardless, I’m definitely delighted I came across it and I’ll be book-marking it and
    checking back frequently!

  2. Avatar
    Ηγουμενίτσα Ανκόνα about {{count}} years ago:

    Hello! I coud have sworn I’ve been to this website before but afrter browsing through
    many oof thhe posts I realized it’s neew to me.
    Regardless, I’m definitely delighted I came across itt and I’ll be
    book-marking it aand checking back frequently!

  3. Avatar
    Houston about {{count}} years ago:

    Hello There. I found your blog the sage of msn. That is a really smmartly written article.
    I’ll be sure to bookmark it and return to learn extra of your helpful information. Thank you for the post.I’ll certainly comeback.

  4. Avatar
    Houston about {{count}} years ago:

    Hello There. I found your blog the usage of msn. That is a really smartly written article.

    I’ll be sure to bookmark it and return to learn extra of your helpful information. Thank you for the post.

    I’ll certainly comeback.

  5. Avatar
    Isabella about {{count}} years ago:

    Hi there, all is going fine here and ofcourse every one iis sharingg information, that’s trulky excellent,
    keep up writing.

  6. Avatar
    Isabella about {{count}} years ago:

    Hi there, all is goibg fine here and ofcourse everyy one is sharing information, that’s
    trulky excellent, keep up writing.

  7. Avatar
    Επιβατηγά πλοία about {{count}} years ago:

    I love reading ann article that can make men and women think.
    Also, maany thanks for permitting me to comment!

  8. Avatar
    Επιβατηγά πλοία about {{count}} years ago:

    I love reading an article that can make men and women think.
    Also, many thanks forr permitting me to comment!

  9. Avatar
    Passenger ships Bari Patras about {{count}} years ago:

    Do you have a spam issue on this blog

  10. Avatar
    Passenger ships Bari Patras about {{count}} years ago:

    Do you have a splam issue on this blog

Leave a comment