Startup script

I have installed php on the router for basic rest api implementation. If I fire below command from putty, my server starts and I can browse the page.

 php-cli -S -t /www

Somehow If I want startup script that runs along with boot, so that page is always available, below script is not working. can you help ? This script is visible in UI as well but always marked as disabled.

#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007
start() {        
        echo php started
        # commands to launch application
	php-cli -S -t /www &&
stop() {          
        echo stop
        # commands to kill application 

Just enable it in the UI.

LuCI > System > Startup and select Disabled to set it to Enabled

1 Like

Or set to enabled (= create a symlink in /etc/rc.d/ to the init script) by running /etc/init.d/yourscriptname enable from SSH console.

(That is the action that the LuCI button triggers.)

When I set this script and reboot the router.

I get following error when I enable it.. its always marked as disabled. I think there is something missing.

There is some thing wrong at the end of command where && is used. Not sure if its required or not. If I remove it works, but looks after some times php server gets killed.

This leaves me to believe you’ve derived the code from somewhere else.

Is your intent to run this in background?

1 Like

Double && means "run next the command after &&", and there should be a command on the line after &&

A single & would mean a detached process to be run on the background.

I have a hunch that you are aiming for either

  • php-cli -S -t /www &
  • (php-cli -S -t /www )&
    which would be a detached shell.

Once of those might work for you if you want to keep the process run even after the script should complete. I would go with the latter version.

Ps. google for Linux shell detach process , and you should get more info.

1 Like