I have Ubuntu Bash installed on Windows 10. How do I have redis-server start up in the background without having to run sudo service redis-server restart each time I initially open a terminal?

I tried adding that command to my ~/.bashrc file, but that causes me to have to enter my password each time I open a terminal window. It also restarts the server every time I open a terminal window. Does anyone know of a better way of me handling this?

  • No clue about WSL but it sounds like your problem is caused by sudo requiring a password, so you can call visudo and set nopasswd: askubuntu.com/questions/334318/…, second part, does that write service write a PID file? If so you can check if it exists and if so check if the process exists before you start the service. – T Nierath May 17 '18 at 12:53
  • Dose the service run in background after closing CMD window? Type service xyz start and close the CMD window. You may see that service is running in task manager. Which Windows version are you running? – Biswapriyo May 17 '18 at 21:14
  • I'm running Windows 10 Pro Build 1803. I do believe it's running in the background after I close the terminal, because it works after closing out all of the terminals. – fwaokda May 18 '18 at 12:11
  • @TNierath, seems like I'd have to write a bash script. I can check and try to do it that way, but might take me a bit. I ever write bash scripts. – fwaokda May 18 '18 at 12:13

I use this for starting sshd once upon login to termux on android, your problem sounds very similar. If your process creates a .pid file then it should be easy to replace ssh with your server binary and copy everything into .bashrc

# check if pid file exists in path (termux path), if so,
#   check if process id is still running, if so,
#     do nothing
# otherwise start sshd

if [ ! -f $HOME/../usr/var/run/ssh.pid ] \
       || ps|grep $(cat $HOME/../usr/var/run/ssh.pid)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.