HOWTO Create a Service: Difference between revisions

From Pumping Station One
No edit summary
No edit summary
Line 64: Line 64:


     exit
     exit


=== Enabling Your Service ===
=== Enabling Your Service ===
Line 75: Line 74:


     sudo systemctl enable strup
     sudo systemctl enable strup


The service is now configured to start when the machine reboots.
The service is now configured to start when the machine reboots.

Revision as of 12:06, 6 August 2014

Philosophy

  • ease of use
  • pass off project maitinance

working on sally

All members have shell and admin access on sally.

   ssh hef@sally.ad.pumpingstationone.org
   sudo uname -a

Create service environment

Create a system account for your service

   sudo useradd strup -b /srv/ -m -r

Working With SystemD

Create a unit file: /etc/systemd/system/strup.service

[Unit]
Description=Strup IRC bot

[Service]
Type=simple
User=strup
Group=strup
ExecStart=/usr/local/bin/ircbot
WorkingDirectory=/srv/strup/

[Install]
WantedBy=multi-user.target

start service, check for log output, etc

   sudo systemctl start strup.service
   sudo systemctl status strup.service


To follow log output:

   sudo journalctl -u strup.service -f


Initially, in my example, I see <quote>ircbot: /home/PS1/hef/projects/strup/irc/main.cpp:45: int main(int, char**): Assertion `file.is_open()' failed.</quote> because I havn't created a file yet.

working with service files

If you tried to see your service user's home directory earlier, you may have noticed it didn't work. switch to your service accounts users.

   sudo su strup
   cd

My example requires a file from project gutenberg.

   wget http://www.gutenberg.org/cache/epub/11/pg11.txt

Don't forget to switch back to your normal user when done

   exit

Enabling Your Service

After verifying that the service is starting and running correctly:

   sudo systemctl status strup

Enable the service

   sudo systemctl enable strup

The service is now configured to start when the machine reboots.