1

I used this answer as a guide to help me writer a startup script for systemd to start my Jenkins container when my machine boots up. However, the script is not working. Here is the script:

[Unit]
Description=Docker container that houses the Jenkins build service.
After=network-online.target

[Service]
Group=docker
ExecStart=/usr/bin/docker start jenkins
ExecStop=/usr/bin/docker stop jenkins

[Install]
WantedBy=multi-user.target

I placed it in /etc/systemd/system/jenkins.service.

When I run sudo systemctl start jenkins, nothing happens. No errors or anything printed out, and the container does not start (if I run docker ps, there are no containers listed as running).

I can run /usr/bin/docker start jenkins from the command line manually and it starts perfectly fine, so the issue seems to be in the way I've written the script, but I can't figure out why it's not working as expected. Any help is appreciated.

wheeler
  • 662

2 Answers2

0

Instead of putting your script in /etc/systemd/system/jenkins.service, put a command inside the ~/.bashrc so that your script runs automatically everytime you boot in Ubuntu (this will be the same command which you used to run your script from terminal). This is a bash file which runs whenever your PC boots up in Ubuntu.

For example if I want /home/Kanishk/Pictures/Delhi.png to run whenever I start Ubuntu, I'll put the command shotwell /home/Kanishk/Pictures/Delhi.png at the end of ~/.bashrc file so that Shotwell will open my picture.

If you rather want to run your Jetkins package instead of that script, put a command to run that instead of the script.

0

I answered a similar question here for another linux distribution. The solution works with systemd to enable the /etc/rc.local file to run commands at startup.

There are some details in the script of that case that you are not using in here:

sudo vim /etc/systemd/system/rc-local.service

Then add the following content to it.

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local

[Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99

[Install] WantedBy=multi-user.target

Try using other options for the script to activate logs and figure out what is going on, like:

[Manager]
LogLevel=info
LogTarget=syslog|console

There are a myriad of other options for the systemd configuration that you may use.

Obviously the solution of including the command in the ~/.bashrc file will only run the command when a single user logs in, not a systemwide solution.

ram0nvaldez
  • 109
  • 1
  • 1
  • 8