Services with Golang - DhruvSingh861/Netcore_Assignment GitHub Wiki
create go runable service file that runs in demon.
- create
service_name.service
file insideComputer/etc/systemd/system
. - edit file using
sudo nano GetEmployee.service
.
[Unit]
Description=GetEmployee Go API to get all employees from postgres test.employe1 table
After=network.target
[Service]
ExecStart=/Home/Documents/netcore/Go_Projects/Services/API
Restart=always
User=nobody
Group=nogroup
Environment=GODEBUG=madvdontneed=1
WorkingDirectory=/Home/Documents/netcore/Go_Projects/Services/API
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
then reloadsudo systemctl start GetEmployee
start the servicesudo systemctl status GetEmployee
check status of your service.sudo journalctl -u GetEmployee
to check log file.sudo systemctl stop GetEmployee
stop service.
Cron Job : Crontab
Example of job definition:
.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
| | | | .---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * user-name command to be executed
* * * * * ./Documents/netcore/Go_Projects/Services/Cron/HelloCron
this command will run HelloCron go build file in the duration of every 1 sec.
nohup
In Linux, the nohup command stands for "no hang up." It allows you to run commands or processes that continue running even after you log out of the terminal or close the session.
nohup command > output.txt &
This will redirect the output of the command to the file output.txt
If you want to keep your processes/jobs running, precede the command with nohup as shown below. The jobs will still continue running in the shell and will not get killed upon exiting the shell or terminal.
nohup ./hello.sh