0
votes

I have a simple Django code which I want to keep running on a specific GCE instance. Sometimes the instance gets restarted due to some reasons, not in my control. I created a batch script which I tried to put in Startup folder in both users and common folder. It didn't work. I tried putting the script in using sysprep-specialize-script-url(using cloud storage), sysprep-specialize-script-cmd and sysprep-specialize-script-bat. It didn't work. Here's the content of the batch script -

cd C:\Users\kartik_domadiya\Desktop\happierMiscGoogleCloud

manage.py runserver 0.0.0.0:80

pause

I tried running C:\Program Files\Google\Compute Engine\metadata_scripts\run_startup_scripts.cmd manually and it worked (with any metadata key). So I can see that there's no problem with the script itself.

I even tried with putting the batch script in task scheduler which didn't work too.

So is there any way I can debug the problem and find out why isn't the batch script working? I am using Windows 2012 R2, if that matters.

PS: I know that's a development server and should not be used in production.

1
You aren't using full paths. You are at the mercy of system configuration.ACatInLove
@ACatInLove I am changing the directory in the batch script, if that's what you mean by full path. Is that what you meant?noob
No I mean all files are FQFN (fully qualified file names). There are many points of failure (I see 4 in your script on the first two lines). All of them depend on configuration, one is possible access denial and two are not using full paths to specify what you want and the fourth relying on file association configuration. Typing in an interactive command prompt you are using helpful features to help users but this is not reliable when programming. I would do "c:\folder\py.exe" "C:\someotherfolder\manage.py" runserver 0.0.0.0:80.ACatInLove
And if you aren't the user running it, get it out of your profile. Also programs are generally blocked from running from the web without user Ok (security).ACatInLove
Also your third line only works if windows thinks you can see it. Start in Task Scheduler (without choosing Run Only When User Logged In) and pause will be ignored.ACatInLove

1 Answers

0
votes

I moved the code to C:/code (basically out of any particular user's folder) and then provided all user its access (Right Click > Properties > Security), updated the batch file and put it into startup folder (Run > shell:startup).
It started working after that. I suppose the issue was due to access permission.