SystemD linux terminal commands

  • sudo systemctl is-enabled service.service

Checks whether the service is enabled or not

  • sudo systemctl enable service.service

enables the service to auto-start at boot time

  • sudo systemctl disable service.service

disables the service with name service for auto-start at boot time.

  • sudo systemctl daemon-reload

Reloads the systemctl unit files. This command should be executed after any change in unit files are made

  • sudo systemctl restart service.service

Restarts the service named service

  • sudo systemctl status service.service

Gets the current status of the service named service

  • sudo touch filename.service

create a text file

  • sudo cp filename newfilename

Make a copy of the file

  • sudo nano filename

open a file

  • shutdown -r now

Restarts the ubuntu server from the command line

  • ps -ef | grep service

Get the process id for the service with the name service

  • sudo kill -9 process_number

kills the process with process id “process_number”

  • cd /etc/systemd/system

change the current directory to the directory where all the unit files are located

  • sudo systemctl edit service.service

Edits the unit file for service.service

  • an Example of Unit file for a java process

———————————————————————————–

[Unit]

Description=nearbyshops_sds: Nearbyshops Service Discovery Service

After=syslog.target network.target

[Service]

WorkingDirectory=/nearbyshops/sds
ExecStart=/usr/lib/jvm/java-8-openjdk-amd64/bin/java -cp /nearbyshops/sds/sds_api_2feb17.jar org.nearbyshops.sds.Main
Type=simple

Restart=always

[Install]

WantedBy=multi-user.target

——————————————————————————————-

 

Links and References

Link : https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples

https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units

https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files?utm_medium=btb_algo

An Example of a unit file

Link : http://stackoverflow.com/questions/32015406/execute-java-jar-via-systemd-service-script-fedora-22

An Example of how to create a unit file from scratch

Link : https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html