Jenkins execute shell standard terminal required error - linux

I have Jenkins master-slave setup and had a job that is going to execute on slave machine.
Inside job configuration I have some Linux commands like:
shutdown the tomcat
start the tomcat
that are being executed in the Jenkins execute shell and require sudo permission.
When I switch the user using
su -
for running all the commands as root user It is giving me the error standard in must be a tty
Even I tried running the command with sudo but it failed.
Note : I have Jenkins Master-slave setup on AWS EC2 so I had few restrictions like :
I can not set password for root user
Can not give full access to the tomcat directory
Adding user to the sudoers
Kindly help me out.

Related

If AWS Sessions Manager executes a file in EC2, which user in the executed EC2 executes the file?

When I execute a sh file in EC2 using AWS Sessions Manager's Run Command, does the user (root or other user I created) configured in the executed EC2 execute the sh? Also, how do I know which user executed it?
It runs as root. You can simply check it by running the following command in Run Command:
whoami > /tmp/info
Then login to the instance and check /tmp/info. You can do same for working directory pwd >> /tmp/info or any parameter you want to check.

when starting jenkins it is starting but when checking status of jenkins it is saying active(exited)

I had changed the permissions of /home/centos to sudo chmod -R 777 /home on which jenkins is hosted after that i'm not able to login to the machine then i had created one more instance and detached the jenkins disk attached to new machine changed the permissions then attached the disk to the jenkins machine. From then i'm able to login but when starting the jenkins it is saying active(exited).
As it is regarding with the permission' i tried to run 'jenkinsuser=root' it worked fine.

Gitlab Executor TTY

I'm trying to leverage Gitlab Runner to execute builds on remote machine. I have the runner and am using the shell executor to kick off builds locally. Unfortunately, I'm receiving the following error when I kick off something:
Using Shell executor...
standard in must be a tty
ERROR: Job failed: exit status 1
I suspect this is occurring because the user that I'm passing in with the --user parameter can access tty. Any thoughts on how to get this working? The shell type is bash.
Check first if GitLab is doing a sudo once connected to the remote machine, to change user.
If that is the case, with visudo (on that remote machine), do:
Defaults:[username] !requiretty
If not, as in here, check if this is a JVM initialization issue.

running SSH script command from jenkins using SSH

To deploy application on linux ubuntu server I have bunch of SSH commands that i currently run using PuTTY. The server has local account serviceaccount1. In PuTTY i connect to server using serviceaccount1 and executes the following commands one by one
cd /home/serviceaccount1/cr-ml
script /dev/null
screen -S data_and_status
cd cr-ml/notebooks
source activate crml
unset XDG_RUNTIME_DIR
jupyter kernelgateway --api='kernel_gateway.notebook_http' --seed_uri='data_and_status_api.ipynb' --port 8894 --ip 0.0.0.0
...
...
and so on
Now i want automate this using Jenkins. I installed SSH plugin, configured credential using SSH Username serviceaccount1 with private key
Then created a new jenkins project and added a build step Execute shell scripts on remote host using ssh and then add all the above commands.
When i build the jenkins project, it get stuck at executing 2nd command script /dev/null
i see the following console output
To me, it seems the culprit is the screen -S data_and_status command. Once you start a screen, I don't think you would be able to execute the subsequent commands over the SSH connection.
Alternatively, you can try using a tool like Ansible to run a bunch of commands against a remote server.

ElasticBeanstalk - Adding ec2-user to another group

I have a cron job that needs to be run under ec2-user on my EC2 instance and it needs to be able to write to the standard log files for my web app. However, the log files are owned by webapp (as per normal).
I've successfully changed the permissions on the log files so that they are accessible by both the owner and the group webapp:webapp. But where I'm running into trouble is when I try to add the ec2-user to the webapp group.
I can do it fine in SSH with sudo usermod -a -G webapp ec2-user but when I try to add this command via EB container-commands, I get an error saying that you must have a tty to run sudo. Running the command without sudo gives me /bin/sh: usermod: command not found.
Anybody know of any other way to be able to add ec2-user to the webapp group via the Elastic Beanstalk deployment config.
Not sure about the issue with the sudoers file, but generally a cleaner way to add a user to a group (than manually executing a command) is to use the users section of the .ebextensions file. For example, in .ebextensions/something.config:
users:
ec2-user:
groups:
- webapp
You should not use sudo, the deploy script is ran by root.
Also, this is a server command, do it in the commands section instead of container commands section.
commands:
01_set_user_role:
command: "usermod -a -G webapp ec2-user"
You need to run this command from a container_command before executing any commands with sudo:
echo Defaults:root \!requiretty >> /etc/sudoers
In context (in .ebextensions/yourconf.config)
container_commands:
001-enableroot:
command: echo Defaults:root \!requiretty >> /etc/sudoers #disables error related to needing a tty for sudo, allows running without cli

Resources