2

I have a 14.04 server running samba. I'd like to institute some time based access to the server. I host media for the whole house, and the goal is for the kids' televisions to become useless at a certain time. I have placed the following into root's crontab:

  0 22 *    *   0-4   /etc/init.d/samba stop 
  0 22 *    *   0-4   /etc/init.d/smbd stop 
  0 22 *    *   0-4   /etc/init.d/nmbd stop 

The shares continue to be active passed the noted time. What am I doing wrong?

1 Answer 1

1

Your commands are not working because /etc/init.d/smbd and /etc/init.d/nmbd have the following at the start:

if init_is_upstart; then
                        exit 1
                fi

So, as the init in ubuntu is now Upstart (/etc/init.d/ is from SysV), you need to run the start-stop scripts from the directory /etc/init/. /etc/init.d/ still exists for backward compatibility because many programs still use this directory.

To make things easier for you, Ubuntu has service command:

sudo service smbd stop
sudo service nmbd stop

While running as root:

service smbd stop
service nmbd stop

service will first search in /etc/init/ directory and then /etc/init.d/. service is efficient in another sense that if there are two scripts having the same name in those two directories (as in case of smbd and nmbd) the Upstart script (in /etc/init/) will take precedence over SysV script (in /etc/init.d/).

Also your cron entry can be made simpler:

0 22 * * 0-4  service samba stop && service smbd stop && service nmbd stop

&& ensures that the next command is run only if the previous one is successful (i.e. exit code $?=0).

2
  • So the init.d scripts are irrelevant now? Thanks for the help Apr 12, 2015 at 16:24
  • init.d scripts are kept for backward compatibility as many programs still use those scripts.
    – heemayl
    Apr 12, 2015 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .