4

I want to let sslocal command automatic start up so I write in /etc/rc.local

sudo sslocal -c /etc/ss.json -d start 
plank
exit 0

but after I restart , sudo systemctl status rc-local it shows that

rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: failed (Result: exit-code) since   2017-12-07 16:05:51 +08; 6min ago
  Process: 1155 ExecStart=/etc/rc.local start (code=exited, status=1/FAILURE)

December 07 16:05:46 lucas-CW65S rc.local[1155]: INFO: loading config from /etc/ss.json
December 07 16:05:50 lucas-CW65S rc.local[1155]: 2017-12-07 16:05:50 INFO     loading libcrypto from libcrypto.so.1.0.0
December 07 16:05:50 lucas-CW65S sudo[1158]: pam_unix(sudo:session): session closed for user root
December 07 16:05:51 lucas-CW65S rc.local[1155]: Failed to connect to Mir: Failed to connect to server socket: no file and directory
December 07 16:05:51 lucas-CW65S rc.local[1155]: Unable to init server: cannot connect : deny connect
December 07 16:05:51 lucas-CW65S rc.local[1155]: [WARN 16:05:51.155503] [Gtk] cannot open display:
December 07 16:05:51 lucas-CW65S systemd[1]: rc-local.service: Control process exited, code=exited status=1
December 07 16:05:51 lucas-CW65S systemd[1]: Failed to start /etc/rc.local Compatibility.
December 07 16:05:51 lucas-CW65S systemd[1]: rc-local.service: Unit entered failed state.
December 07 16:05:51 lucas-CW65S systemd[1]: rc-local.service: Failed with result 'exit-code'

the key point may be sudo[1158]: pam_unix(sudo:session): session closed for user root and it seems that it need sudo password when switch to sudo status, but how can I input it in rc.local file ?..

2

You've two problems there.

  1. /etc/rc.local runs as root, so you don't need sudo
  2. rc.local is a script, these are sequential and each command blocks execution. Run your commands in background by adding & at the end.

Also note that rc.local uses #!/bin/sh -e which means it will exit on any error. If you want the script to continue execution even if one of commands fails, use command arg1 arg2 || true type of approach.

2

Simple fix: remove the word "sudo" from your script.

Reason: /etc/rc.local already runs as root, so you don't need a sudo there.

PS: You should not be calling sudo from a shell script for whatsoever reason.

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.