I have lack of understanding. Do i need to include forking in my bash script: https://stackoverflow.com/a/26756839/4749164, so i can use expect daemon/fork - option in upstart?

i would like to run my bash script as process in background through upstart, so far i did:

start on filesystem or runlevel [2345]
stop on shutdown or runlevel [12345]

expect daemon

  export HOME="/user"
  echo $$ > /var/run/bashscript.pid
  exec /etc/rfid/bashscript
end script

pre-start script
   echo "[`date`]" program starting >> /var/log/bashscript.log
end script

pre-stop script
   rm /var/run/program.pid
   echo "[`date`]" program stopping >> /var/log/bashscript.log
end script

when i run in terminal: sudo service bashscript status it says that bashscript is running and it has Pid which is true if i check: /var/run/bashscript.pid But there is no such process running in top with that pid and if i type in terminal: sudo service bashscript stop it hangs. What am i doing wrong or missing?

  • This looks like an XY problem. What are you actually trying to accomplish? – Sobrique May 1 '15 at 11:14
  • For start i would like to run my bash script as service - process. After that i would like to know what needs to be done to achieve subprocessing.. – ticket May 1 '15 at 11:48
  • Likely the problem lies in /etc/rfid/bashscript and it's exiting abnormally. – Sobrique May 1 '15 at 11:57
  • Can you please explain what were you thinking with that? bashscript has no extension because its executable and there is no need to include exec bash -c because my bashscript has shebang at beginnig of code, so i don't think that's the problem... or am i wrong? – ticket May 1 '15 at 12:24
  • Depends - does it sit in a loop and keep running, and is the environment at boot time when it's called appropriate for it to 'work'? – Sobrique May 1 '15 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.