1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Starting, Stopping and Restarting Services from CLI Command Line via SSH or Telnet

Discussion in 'Tomato Firmware' started by ooglek, Jul 4, 2008.

?

Did you find this post useful?

Poll closed Aug 3, 2008.
  1. Yes! I can now master my router via SSH.

    1 vote(s)
    100.0%
  2. Maybe, it's a bit confusing though.

    0 vote(s)
    0.0%
  3. No, I can't figure out WTF you are talking about.

    0 vote(s)
    0.0%
  1. ooglek

    ooglek Addicted to LI Member

    So in a recent post I asked how I could remotely enable and disable HTTP remote management via SSH command line. Ultimately I got bored, downloaded the source, and found my answer. Read the post if you want to know just that.

    Here's a list of commands that you can issue on the commandline CLI on your Tomato Firmware-running router to re-read NVRAM settings and act accordingly.

    As an example, I'm using admin-restart.
    1. Modify NVRAM settings accordingly
    2. nvram set action_service=admin-restart
    3. kill -USR1 1

    Replace "admin-restart" with any one of the below strings to restart only a portion of the services Tomato runs. You're on your own to figure out what nvram settings you need to change to do what you want, but viewing the source of the web page SHOULD give you some strong suggestions. All of these commands are found in the .asp files in the source, and are strongly linked to certain pages, if not a one-to-one relationship.

    It seems that sending a SIGUSR1 to init (always PID 1) will cause Tomato to read the nvram action_service setting, and then act accordingly. When action_service is empty, SIGUSR1 doesn't seem to do anything. I didn't download the source from Linksys, so I'm guessing, but it seems to work.

    Running kill -HUP 1, or SIGHUP to init, seems to restart ALL service. Not really a reboot, but painfully close to it. Will likely take down your internet connection for a moment, as EVERYTHING will restart. NOTE: action_service is reset to an empty string after you run a SIG USR1 to init, so subsequent signals to init will do nothing, unless you reset action_service to whatever string is appropriate.

    • * -- Everything, I think. Does the same as "kill -HUP 1"
    • admin-restart -- All administrative services, such as SSH, Telnet, HTTP, HTTPS, both local and remote
    • cifs-restart -- CIFS services for your CIFS mounts
    • ctnf-restart -- Advanced Conntrack and Netfilter, everything in Advanced > Conntrack/netfilter Web interface
    • ddns-restart -- Dynamic DNS services
    • dhcpd-restart -- DHCP
    • dns-restart -- DNS Services
    • dnsmasq-restart -- Dnsmasq Services (a lightweight, caching DNS proxy with integrated DHCP server)
    • firewall-restart -- Anything firewall related
    • jffs2-restart -- JFFS2 Services
    • logging-restart -- Logging Services
    • ntpc-restart -- NTP Services
    • qos-restart -- Quality of Service Services
    • restrict-restart -- Access Restriction Services
    • routing-restart -- Routing Services
    • rstats-restart -- Restart Bandwidth Monitoring Settings and Services
    • rstatsnew-restart -- Same as rstats-restart, but reset and start new file
    • sched-restart -- Scheduler Services, like timed Reboot, Reconnect, and Custom scripts
    • upnp-restart -- Port Forwarding UPNP Services

    There you have it. Now you SHOULD be able to manage your Tomato Router free from the web interface. I'm sure there are a few things that cannot be done, but I doubt it. Doing it in the web interface, viewing the source to see what NVRAM settings the web interface modifies, and then viewing the nvram settings from the CLI will help speed your nimbleness in the CLI management of your Tomato Router.
     
  2. mstombs

    mstombs Network Guru Member

    I think you should have also a look at the "service" command, seems easier than above ie

    service dnsmasq restart
    service wlan stop

    etc
     
  3. ooglek

    ooglek Addicted to LI Member

    Damn! That is easier. Crap.

    Holy Crap! That is easier. Why didn't you reply before I reversed engineered it?!? :wink:

    When you reverse engineer that which the web interface is doing, and when the CLI is not quite as well documented, you end up with the convoluted.

    Is there a place where all of the services you can use with service are documented? I'd love it if I didn't have to restart ALL the the admin services, maybe just the web-based admin restart. I've googled and searched the forums linked from PolarCloud.com, but have not found what I'm looking for.
     
  4. mstombs

    mstombs Network Guru Member

    Sorry!

    Look in services.c

    The command is

    Code:
    service <service> <action>
    where 
    <action> is 
    start, stop, restart
    
    <service> is
    dhcpc
    dhcpd
    dns
    dnsmasq
    firewall
    restrict
    qos
    upnp
    telnetd
    sshd
    admin
    ddns
    ntpc
    logging
    crond
    upgrade
    cifs
    jffs2
    routing
    ctnf
    wan
    net
    rstats
    rstatsnew
    sched
     
  5. dissident

    dissident Addicted to LI Member

    I'm running Tomato on a WRTSL54GS and was hoping to find a way to enable/disable QoS from the command line (actually, using the Plink.exe component of PuTTY). The reason for this is that sometimes I do huge FTP uploads, and I want the absolute maximum upload speed my connection can deliver, unrestrained by QoS.

    Is "service qos stop" and "service qos start" what I'm after?
     
  6. ooglek

    ooglek Addicted to LI Member

    I'm fairly sure that's it. service admin restart worked exactly as expected, and I'm guessing QOS will work the same way. service qos stop will emulate you unchecking "Enable QOS" and hitting save, and service qos start will emulate you checking "Enable QOS" and hitting save. Try it out and report back.
     
  7. dissident

    dissident Addicted to LI Member

    I can confirm that "service qos start" and "service qos stop" do exactly what is expected--they start or stop the QoS service. What they do not do is toggle the "Enable QoS" setting in Tomato under QoS > Basic Settings. That setting remains on even after QoS is stopped.

    To test the efficacy of my command lines, I set "Max Bandwidth" to an artificially low value, that being 50 kbit/s. With QoS enabled initially, I ran an FTP upload and noted its speed. Because of my QoS settings, the upload was going very slowly. Then I ran the command line (this is in a batch file, with "Tomato" being a PuTTY profile I have set up):

    Code:
    start "" /wait "C:\Program Files\PuTTY\plink.exe" -load Tomato echo;echo Disabling QoS...;echo;service qos stop;el=$?;echo Return code: $el; sleep 5
    As soon as QoS was shut down, the FTP upload began picking up speed. The reverse case was (not surprisingly) observed when this was run:

    Code:
    start "" /wait "C:\Program Files\PuTTY\plink.exe" -load Tomato echo;echo Enabling QoS...;echo;service qos start;el=$?;echo Return code: $el; sleep 5
     
  8. ooglek

    ooglek Addicted to LI Member

    Fab! Thanks for the reply, and nice automation scripts! :)

    I suppose that the service qos stop stops the QOS service (duh), and doesn't modify the actual QOS settings, such as the checkbox you reported as unchanged. That makes sense. Though I suspect that the command does the same sort of thing as if you unchecked "Enable QOS" and hit save; the service command simply wouldn't start up QOS when told to start, as the settings would be different. Same result, different methods. You wouldn't want to change the settings just to stop and start the service.
     

Share This Page