2013-05-04 73 views
5

我正在嘗試設置流浪虛擬機來支持我通過Seven Databases in Seven Weeks進行學習。我使用在sudo環境中執行適當操作的基本shell腳本供應軟件。但是,我正在使用vagrant用戶來運行教程,並希望供應將適當的節點/ NPM模塊安裝爲Vagrant,而不是通過sudo。如何在沒有sudo的情況下使用Vagrant配置軟件

我當前的npm命令是此配置腳本中的最後一行,但vagrant嘗試執行節點腳本時該模塊不可用。

apt-get update 
apt-get -y install build-essential 
apt-get -y install tcl8.5 
wget http://redis.googlecode.com/files/redis-2.6.0-rc3.tar.gz 
tar xzf redis-2.6.0-rc3.tar.gz 
cd redis-2.6.0-rc3 
make 
make install 
make test 
mkdir /etc/redis 
mv redis.conf /etc/redis/redis.conf 
sed -i.bak 's/127.0.0.1/0.0.0.0/g' /etc/redis/redis.conf 
sed -i.bak 's/daemonize no/daemonize yes/g' /etc/redis/redis.conf 
sed -i.bak 's/dir .\//dir \/var\/lib\/redis/g' /etc/redis/redis.conf 

cd src/ 
wget https://raw.github.com/gist/1053791/880a4a046e06028e160055406d02bdc7c57f3615/redis-server 
mv redis-server.1 /etc/init.d/redis-server 
mv redis-cli /etc/init.d/redis-cli 
chmod +x /etc/init.d/redis-server 
sed -i.bak 's/DAEMON=\/usr\/bin\/redis-server/DAEMON=\/usr\/local\/bin\/redis-server/g'  /etc/init.d/redis-server 
useradd redis 
mkdir -p /var/lib/redis 
mkdir -p /var/log/redis 
chown redis.redis /var/lib/redis 
chown redis.redis /var/log/redis 
update-rc.d redis-server defaults 
/etc/init.d/redis-server start 
cd /etc/init.d/ 
echo ./redis-cli 
echo http://blog.hemantthorat.com/install-redis-2-6-on-ubuntu/ 

apt-get -y install python-software-properties python g++ make 
add-apt-repository -y ppa:chris-lea/node.js 
apt-get update 
apt-get -y install nodejs 

npm install hiredis redis csv 

回答

9

在VagrantFile只需設置privilegedfalse這樣的:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    ... 
    config.vm.provision :shell, privileged: false, path: "script.sh" 
    ... 
end 
1

也許使用npm install -g在vm中全局安裝它?

4

shell規定以root用戶身份運行。如果您能夠爲用戶vagrant運行,你可以做這樣的事情:

sudo -u vagrant npm install hiredis redis 

..或者多行:

sudo -u vagrant << EOF 
[...] 
npm install hiredis 
npm install redis 
EOF 
-1

的sed -i的/.* requiretty $ /默認值!requiretty /'的/ etc/sudoers文件

相關問題