3

I installed vnstats to see bandwidth statistics, I copied an init.d file tempalte, I placed it in init.d directory, it works ok to access this file and do start/restart/status, but this file should start automatically on system boot, correct? It doesn't start, how can I debug this? If after system boot I do init.d/vnstat then it starts.

I am running Centos 5

Thank you.

adrianTNT
  • 1,007
  • 5
  • 21
  • 41
  • most topics mention chkconfig but: "chkconfig: command not found" maybe there is another way ?! – adrianTNT Jan 06 '12 at 23:06
  • Obvious question, have you got chkconfig package installed? Is it in your $PATH environment variable? If you're desperate you can always drop it in rc.local, http://www.linuxquestions.org/questions/linux-newbie-8/rc-local-does-not-work-centos-741197/ else setup symlinks manually but obviously chkconfig is the more 'proper way' of doing things. – dtbnguyen Jan 06 '12 at 23:17
  • Found it installed in /sbin/chkconfig , thanks. – adrianTNT Jan 07 '12 at 10:00

3 Answers3

5

If you write an init script with the correct syntax, you can turn it into a service:

chkconfig --add vnstats

after that, you can turn it on or off for certain runlevels:

chkconfig --level 345 vnstats on

You can also manually start or stop services with the service command, using the functions declared in the script itself. For example, if your script has a function called stop and one called start, you can use

service vnstats stop and service vnstats start

Suggested reading: the official documentation

Kenny Rasschaert
  • 8,925
  • 3
  • 41
  • 58
  • bash: chkconfig: command not found. Should the files in init.d start automatically? Is there another way ? – adrianTNT Jan 06 '12 at 23:04
  • I would expect it to be installed by default, what is the result of running yum info chkconfig – becomingwisest Jan 07 '12 at 00:41
  • Yum said chkconfig WAS installed, so I found it in /sbin/chkconfig and I had to use full path when calling the above instructions: /sbin/chkconfig --add vnstat – adrianTNT Jan 07 '12 at 09:59
  • I have a question tough. Even before the chkconfig --add I seen the service "vnstatd" stopped with --status-all, I am not sure if the -add command should contain vnstat or vnstatd, should it match the file name inside /etc/init.d/ folder? I added it with "--add vnstat" and the service status refers to it as "vnstatd". Thanks. – adrianTNT Jan 07 '12 at 10:02
1

If the init.d has a chkconfig setting, they you can chkconfig --add vnstat; chkconfig vnstat on

Tom O'Connor
  • 27,440
  • 10
  • 72
  • 148
becomingwisest
  • 3,278
  • 19
  • 17
0

You should really follow earlier suggestions of adding a chkconfig section to your initfile, but if you're lazy and want to work around this, you can just symlink the file yourself like this:

ln -s /etc/init.d/vnstat /etc/rc3.d/S90vnstat

If you want to pursue the chkconfig path and lack the chkconfig package, install it with: yum install chkconfig

Mattias Ahnberg
  • 4,039
  • 18
  • 19