1

I have created a script to execute a binary as a service. But the service does not start the service but when i stop the service it shows multiple pids.

I am using RHEL 7.Here is the complete details

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

Usually we run the script as follows ./pipeline --config pipeline.conf

[Unit]
Description=Pipeline service

[Service]
Type=simple
User=cisco
ExecStart=/hfqp/bin/pipeline --config /hfqp/bin/pipeline.conf

and the did the following

systemctl daemon-reload
systemctl start pipeline.service

Even this did not work.

here is the error log

● pipeline.service - Pipeline service
   Loaded: loaded (/etc/systemd/system/pipeline.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2019-04-16 06:29:34 GMT; 19s ago
  Process: 10195 ExecStart=/home/cisco/bigmuddy-network-telemetry-pipeline/bin/executePipeline.sh --daemon (code=exited, status=1/FAILURE)
 Main PID: 9962 (code=exited, status=1/FAILURE)

Apr 16 06:29:07 matrix-pipeline-b-01 systemd[1]: Starting Pipeline service...
Apr 16 06:29:32 matrix-pipeline-b-01 sudo[10196]: pam_unix(sudo:auth): conversation failed
Apr 16 06:29:32 matrix-pipeline-b-01 executePipeline.sh[10195]: sudo: no tty present and no askpass program specified
Apr 16 06:29:32 matrix-pipeline-b-01 sudo[10196]: pam_unix(sudo:auth): auth could not identify password for [cisco]
Apr 16 06:29:34 matrix-pipeline-b-01 systemd[1]: pipeline.service: control process exited, code=exited status=1
Apr 16 06:29:34 matrix-pipeline-b-01 systemd[1]: Failed to start Pipeline service.
Apr 16 06:29:34 matrix-pipeline-b-01 systemd[1]: Unit pipeline.service entered failed state.
Apr 16 06:29:34 matrix-pipeline-b-01 systemd[1]: pipeline.service failed.

Any help is appreciated

  • 2
    Please complete with your distribution name and version. If you are running a systemd based system, you would save time using a systemd unit. – Chaoxiang N Apr 15 at 7:00
  • The typical approach is to record the PID when you start the process in for instance /var/run/pipeline.pid and check for the existence of that PID rather than using ps | grep processname - when you still want to grep running processes ; use pgrep to prevent grep from matching the grep command itself and use the associated pkill - but the better answer this day and age is to write a systemd service unit file as @ChaoxiangN already mentioned. – HBruijn Apr 15 at 7:14
  • @HBruijn I tried both creating the Unit service as well as the script. Either ways it is not working – wandermonk Apr 16 at 5:49
  • You can see from the last log snippet that the script you're trying to run as a service is itself trying to sudo to the cisco user and failing, because it can't do it without prompting for a password, and that there's no way to interactively ask for the password anyway. – bodgit Apr 18 at 12:55
  • Don't attempt to make an old-style init script. These are deprecated, difficult to manage and will not work in the future. – Michael Hampton Apr 18 at 19:47
6
+50

Have you looked into the below error message?

Apr 16 06:29:32 matrix-pipeline-b-01 executePipeline.sh[10195]: sudo: no tty present and no askpass program specified
Apr 16 06:29:32 matrix-pipeline-b-01 sudo[10196]: pam_unix(sudo:auth): auth could not identify password for [cisco]

It seems cisco user is failing to run a command with sudo privileges as this is most likely an non-interactive script. You could grant passwordless sudo by editing the /etc/sudoers file.

$ sudo visudo
# Add a line like this to /etc/sudoers
# username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand
cisco ALL = NOPASSWD: /hfqp/bin/pipeline --config /hfqp/bin/pipeline.conf

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.